Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class android.webkit.WebView happens sporadically in production

my application is on Google Play and it runs fine on most of devices (thousands of users). But in rare cases (fraction of percent of daily active users) I get Error inflating class android.webkit.WebView when I inflate layout for my fragment in onCreateView method. Full stack trace is following:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tapmedia.tapito/com.tapmedia.tapito.LockscreenActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class android.webkit.WebView    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2694)    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)    at android.app.ActivityThread.access$900(ActivityThread.java:178)    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)    at android.os.Handler.dispatchMessage(Handler.java:102)    at android.os.Looper.loop(Looper.java:145)    at android.app.ActivityThread.main(ActivityThread.java:5944)    at java.lang.reflect.Method.invoke(Method.java)    at java.lang.reflect.Method.invoke(Method.java:372)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.webkit.WebView    at android.view.LayoutInflater.createView(LayoutInflater.java:640)    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)    at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)    at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)    at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)    at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)    at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)    at android.app.Activity.performCreate(Activity.java:6289)    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)    at android.app.ActivityThread.access$900(ActivityThread.java:178)    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)    at android.os.Handler.dispatchMessage(Handler.java:102)    at android.os.Looper.loop(Looper.java:145)    at android.app.ActivityThread.main(ActivityThread.java:5944)    at java.lang.reflect.Method.invoke(Method.java)    at java.lang.reflect.Method.invoke(Method.java:372)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.reflect.InvocationTargetException    at java.lang.reflect.Constructor.newInstance(Constructor.java)    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)    at android.view.LayoutInflater.createView(LayoutInflater.java:614)    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)    at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)    at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)    at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)    at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)    at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)    at android.app.Activity.performCreate(Activity.java:6289)    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)    at android.app.ActivityThread.access$900(ActivityThread.java:178)    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)    at android.os.Handler.dispatchMessage(Handler.java:102)    at android.os.Looper.loop(Looper.java:145)    at android.app.ActivityThread.main(ActivityThread.java:5944)    at java.lang.reflect.Method.invoke(Method.java)    at java.lang.reflect.Method.invoke(Method.java:372)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview    at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:161)    at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)    at android.webkit.WebView.getFactory(WebView.java:2193)    at android.webkit.WebView.ensureProviderCreated(WebView.java:2188)    at android.webkit.WebView.setOverScrollMode(WebView.java:2247)    at android.view.View.(View.java:3795)    at android.view.View.(View.java:3909)    at android.view.ViewGroup.(ViewGroup.java:507)    at android.widget.AbsoluteLayout.(AbsoluteLayout.java:55)    at android.webkit.WebView.(WebView.java:547)    at android.webkit.WebView.(WebView.java:492)    at android.webkit.WebView.(WebView.java:475)    at android.webkit.WebView.(WebView.java:462)    at java.lang.reflect.Constructor.newInstance(Constructor.java)    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)    at android.view.LayoutInflater.createView(LayoutInflater.java:614)    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)    at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)    at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)    at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)    at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)    at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)    at android.app.Activity.performCreate(Activity.java:6289)    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)    at android.app.ActivityThread.access$900(ActivityThread.java:178)    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)    at android.os.Handler.dispatchMessage(Handler.java:102)    at android.os.Looper.loop(Looper.java:145)    at android.app.ActivityThread.main(ActivityThread.java:5944)    at java.lang.reflect.Method.invoke(Method.java)    at java.lang.reflect.Method.invoke(Method.java:372)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview    at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:137)    at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:133)    at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)    at android.webkit.WebView.getFactory(WebView.java:2193)    at android.webkit.WebView.ensureProviderCreated(WebView.java:2188)    at android.webkit.WebView.setOverScrollMode(WebView.java:2247)    at android.view.View.(View.java:3795)    at android.view.View.(View.java:3909)    at android.view.ViewGroup.(ViewGroup.java:507)    at android.widget.AbsoluteLayout.(AbsoluteLayout.java:55)    at android.webkit.WebView.(WebView.java:547)    at android.webkit.WebView.(WebView.java:492)    at android.webkit.WebView.(WebView.java:475)    at android.webkit.WebView.(WebView.java:462)    at java.lang.reflect.Constructor.newInstance(Constructor.java)    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)    at android.view.LayoutInflater.createView(LayoutInflater.java:614)    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)    at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)    at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)    at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)    at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)    at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)    at android.app.Activity.performCreate(Activity.java:6289)    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)    at android.app.ActivityThread.access$900(ActivityThread.java:178)    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)    at android.os.Handler.dispatchMessage(Handler.java:102)    at android.os.Looper.loop(Looper.java:145)    at android.app.ActivityThread.main(ActivityThread.java:5944)    at java.lang.reflect.Method.invoke(Method.java)    at java.lang.reflect.Method.invoke(Method.java:372)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

I don't understand what's wrong. Because this error comes from online reporting tool (Crashlytics/Fabric), I can't tell, whether this happens every time the specific user tries to use the fragment or if the user normally gets the fragment inflated and the error happens only from time to time. WebView widget is part of the system, right? I mean - I can't be missing something in my production APK - like support library or so. Or can I?

like image 458
d.aemon Avatar asked Jul 30 '15 19:07

d.aemon


2 Answers

If you see these reports from devices running Android Lollipop, please ignore them. This likely happens whenever something launches an activity that uses WebView while the WebView package is in the middle of being updated by Play Store (which can only happen on Lollipop currently). During updates, packages are treated as not installed by the package manager. That is, there is nothing wrong with your app. The time window while the updated package is considered non-existent is typically small, so when the app is relaunched after such a crash, it will start normally.

like image 126
Mikhail Naganov Avatar answered Sep 20 '22 10:09

Mikhail Naganov


To fix this problem that appears on Android Lollipop you can use a custom WebView that creates a new configuration only on Android Lollipop (API 21 and 22). Replace the WebView on your XML layout with this custom WebView.

import android.annotation.TargetApi; import android.content.Context; import android.content.res.Configuration; import android.os.Build; import android.util.AttributeSet; import android.webkit.WebView;  public class LollipopFixedWebView extends WebView {      public LollipopFixedWebView(Context context) {         super(getFixedContext(context));     }      public LollipopFixedWebView(Context context, AttributeSet attrs) {         super(getFixedContext(context), attrs);     }      public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {         super(getFixedContext(context), attrs, defStyleAttr);     }      // To fix Android Lollipop WebView problem create a new configuration on that Android version only     private static Context getFixedContext(Context context) {         if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) // Android Lollipop 5.0 & 5.1             return context.createConfigurationContext(new Configuration());         return context;     } } 
like image 38
Hector J. Orozco Avatar answered Sep 21 '22 10:09

Hector J. Orozco