创建全局WebView时遇到一个报错,WebViewActivity页面会白屏,google后发现是WebView的bug,详细的WebView的bug介绍详见链接(https://groups.google.com/a/chromium.org/forum/#!topic/android-webview-dev/m0EtO3IXNn0),本来是在MainActivity中创建一个全局webview,结果安装第一次都会报此异常,后来将其改为先在SplashActivity中初始化一次,再在MainActivity中初始化一次,全局WebView便可以正常创建了,代码如下:
- WebViewActivity.java
public static WebView webView;
- SplashActivity.java
onCreate中:
try{
if(WebViewActivity.webView==null){
WebViewActivity.webView=new WebView(SplashActivity.this);
}
}catch(Exception e){
e.printStackTrace();
}
- MainActivity.java
onCreate中:
try{
if(WebViewActivity.webView==null){
WebViewActivity.webView=new WebView(MainActivity.this);
}
}catch(Exception e){
e.printStackTrace();
}
详细的报错日志如下:
Rejecting re-init on previously-failed class java.lang.Class
at com.android.webview.chromium.WebViewContentsClientAdapter com.android.webview.chromium.WebViewChromiumFactoryProvider.createWebViewContentsClientAdapter(android.webkit.WebView, android.content.Context) (WebViewChromiumFactoryProvider.java:328)
at void com.android.webview.chromium.WebViewChromium.init(java.util.Map, boolean) (WebViewChromium.java:42)
at void android.webkit.WebView.
at void android.webkit.WebView.
at void android.webkit.WebView.
at void android.webkit.WebView.
at void android.webkit.WebView.
at void com.xizhulou.gamehello.activity.game.GameWebViewActivity.initWebView(android.content.Context) (GameWebViewActivity.java:172)
at void com.xizhulou.gamehello.activity.game.GameWebViewActivity.init() (GameWebViewActivity.java:125)
at void com.xizhulou.gamehello.activity.game.GameWebViewActivity.onCreate(android.os.Bundle) (GameWebViewActivity.java:77)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6915)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1123)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2746)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2864)
at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1567)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
at void android.os.Looper.loop() (Looper.java:156)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6523)
at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:942)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:832)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.webkit.RenderProcessGoneDetail" on path: DexPathList[[zip file "/system/app/WebViewGoogle/WebViewGoogle.apk"],nativeLibraryDirectories=[/system/app/WebViewGoogle/lib/arm, /system/app/WebViewGoogle/WebViewGoogle.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /system/vendor/lib, /product/lib, /system/lib, /vendor/lib, /system/vendor/lib, /product/lib]]
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at com.android.webview.chromium.WebViewContentsClientAdapter com.android.webview.chromium.WebViewChromiumFactoryProvider.createWebViewContentsClientAdapter(android.webkit.WebView, android.content.Context) (WebViewChromiumFactoryProvider.java:328)
at void com.android.webview.chromium.WebViewChromium.init(java.util.Map, boolean) (WebViewChromium.java:42)
at void android.webkit.WebView.
at void android.webkit.WebView.
at void android.webkit.WebView.
at void android.webkit.WebView.
at void android.webkit.WebView.
at void com.xizhulou.gamehello.activity.game.GameWebViewActivity.initWebView(android.content.Context) (GameWebViewActivity.java:172)
at void com.xizhulou.gamehello.activity.game.GameWebViewActivity.init() (GameWebViewActivity.java:125)
at void com.xizhulou.gamehello.activity.game.GameWebViewActivity.onCreate(android.os.Bundle) (GameWebViewActivity.java:77)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6915)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1123)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2746)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2864)
at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1567)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
at void android.os.Looper.loop() (Looper.java:156)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6523)
at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:942)