Chromium webview does not seems to work with Andro

2019-04-21 13:45发布

问题:

Following my change describe in Force locale for Android flavor with resConfig I am facing a problem with webviews containing video. The issue is only on API21+ and really disappear when removing the call to applyOverrideConfiguration. Not so sure how to get around that.

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
            at com.android.webview.chromium.WebViewContentsClientAdapter.getDefaultVideoPoster(WebViewContentsClientAdapter.java:1172)
            at org.chromium.android_webview.DefaultVideoPosterRequestHandler$1.run(DefaultVideoPosterRequestHandler.java:39)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

From what I could find on grepcode it would be while getting the ic_media_video_poster image.. I validated that this image is really in the sdk. http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.1_r1/com/android/webview/chromium/WebViewContentsClientAdapter.java#WebViewContentsClientAdapter.getDefaultVideoPoster%28%29

public Bitmap More ...getDefaultVideoPoster() {
         TraceEvent.begin();
         Bitmap result = null;
         if (mWebChromeClient != null) {
             if (TRACE) Log.d(TAG, "getDefaultVideoPoster");
             result = mWebChromeClient.getDefaultVideoPoster();
         }
         if (result == null) {
             // The ic_media_video_poster icon is transparent so we need to draw it on a gray
             // background.
             Bitmap poster = BitmapFactory.decodeResource(
                     mWebView.getContext().getResources(),
                     R.drawable.ic_media_video_poster);
             result = Bitmap.createBitmap(poster.getWidth(), poster.getHeight(), poster.getConfig());
             result.eraseColor(Color.GRAY);
             Canvas canvas = new Canvas(result);
             canvas.drawBitmap(poster, 0f, 0f, null);
         }
         TraceEvent.end();
         return result;
     }

EDIT: After a few more test, I was able to isolate the crash in a testApp. It is available in the bugreport I created on Chromium https://code.google.com/p/chromium/issues/detail?id=521753

Any ideas? As anyone faced this problem already?