17

I found a crash report on Crashlytics in a Samsung SM G920F (Galaxy S6), version 5.1.1 (on all other devices I didn't retrieve same error).

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.myactivity}: 
android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView

This is the layout of my webview (the style is an empty style):

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_webview_id"
    style="@style/MyEmptyStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent" />

This is how I include it in activity layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/my_webview_layout"
        android:visibility="gone"/>
</LinearLayout>

The error reported is an XML error so I provided all code (simplified). This is a single report so it happened only one time on this device, can someone explain me why?

EDIT (complete stacktrace)

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.myactivity}: android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.view.InflateException: Binary XML file line #21: 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.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
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.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:174)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:109)
       at android.webkit.WebView.getFactory(WebView.java:2202)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2197)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2256)
       at android.view.View.<init>(View.java:3843)
       at android.view.View.<init>(View.java:3954)
       at android.view.ViewGroup.<init>(ViewGroup.java:513)
       at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
       at android.webkit.WebView.<init>(WebView.java:553)
       at android.webkit.WebView.<init>(WebView.java:498)
       at android.webkit.WebView.<init>(WebView.java:481)
       at android.webkit.WebView.<init>(WebView.java:468)
       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.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:167)
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:146)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:109)
       at android.webkit.WebView.getFactory(WebView.java:2202)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2197)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2256)
       at android.view.View.<init>(View.java:3843)
       at android.view.View.<init>(View.java:3954)
       at android.view.ViewGroup.<init>(ViewGroup.java:513)
       at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
       at android.webkit.WebView.<init>(WebView.java:553)
       at android.webkit.WebView.<init>(WebView.java:498)
       at android.webkit.WebView.<init>(WebView.java:481)
       at android.webkit.WebView.<init>(WebView.java:468)
       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.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70

7 Answers7

9

It seems that something strange ocurred when the app was inflating the WebView, could be whatever.

For the NameNotFoundException: com.google.android.webview I can deduce that could be a problem with the Google packages (The user could be using a custom ROM and not having them installed.)

If you had more info about the terminal with the error I'll say you go for it, but you have to see the proportion of users/users_with_this_error that you have. Then you could see if it's useful for you work in this issue or not.

From breakline's comment: Check out this post, looks kinda like the same issue: NameNotFoundException webview

Community
  • 1
  • 1
arodriguezdonaire
  • 5,396
  • 1
  • 26
  • 50
  • I know that if i don't find a solution the proportion is so small that i don't need to "repair" this issue, but i was just curious – Giorgio Antonioli Aug 03 '15 at 08:59
  • I've edited part of the solution to clarify more the doubt, I'll keep editing until I don't see anything more. – arodriguezdonaire Aug 03 '15 at 09:10
  • I improve your answer with a reference to breakline's comment. I don't want to let this bounty expire with no reasons, so i'll accept your answer as a "summary" for other users – Giorgio Antonioli Aug 03 '15 at 10:06
6

I got the same error on my crashlytics.

After some searches on Google, it seems that this can happen when the user has no webview installed on the phone.

That sounds weird as the webview is a system package, but there is a bug where it is actually possible when the webview package is being updated while the user is using the app. It does not work on all phones, so it can be reproduced on some specific devices (I guess Samsung ones mostly...), but not on others.

I do not remember exactly the step do reproduce it, but something like:

  • start the app
  • go to play store and uninstall the web view updates
  • start to install the updates and switch back to the app
  • on some devices, at the end of the update, the app restart and it works well. On some, the bug appears and if you try to load the webview, it crashes.

Not sure how to deal with it. I guess you can look whether the package exists or register to be notified on package updates to reload the app. In my case, it is really a corner case and happened once or twice, I do not think it requires to work on fixing the issue. If it happens more often, maybe some actions are necessary.

Simon Ninon
  • 2,371
  • 26
  • 43
  • same problem for me.. How to fix this – Ranjithkumar Aug 06 '17 at 17:21
  • 1
    I haven't provided any fix on my side personally. I think you have two ways: either you do a try/catch around the setContentView: if it breaks because of a package not found exception, then you can try to display an error to the client or simply reload the app (not sure what solution is the most appropriate). Or you can register a broadcast receiver on a package updated event and reboot your app for the case of the webview package (https://stackoverflow.com/questions/30727953/android-app-update-broadcast) – Simon Ninon Aug 07 '17 at 02:13
2

As @simon-ninon said, this is the way I implented in my app.

In the onCreate of the activity that inflates Webview in the UI, you can have a try-catch to save yourself from the errors producing in the Crashlytics.

  /**
     * This element touches the UI elements
     * of the application and set them up.
     */
   try {
        setContentView(R.layout.activity_main);
        // ... further setup
    } catch (Exception ex) {
        transferToNoPackageFoundActivity(ex.getMessage());
    }


    private void transferToNoPackageFoundActivity(String errorMessage) {
        Intent intent = new Intent(this, NoPackageFoundActivity.class);
        intent.putExtra(Intent.EXTRA_INTENT, errorMessage);
        startActivity(intent);
        finish();
    }

In the NoPackageFoundActivity, you can take the user to the Playstore for downloading the webview package.

    /**
 * This field is used for presenting the user
 * with an error image for no connectivity.
 */
private lateinit var mErrorImage: ImageView

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_no_network)
    // get the intent for the error message, if any.
    val intent: Intent = intent
    if (intent.hasExtra(Intent.EXTRA_INTENT)) {
        println(intent.getStringExtra(Intent.EXTRA_INTENT))
    }

    mErrorImage = findViewById(R.id.error_image)
    mErrorImage.contentDescription = resources.getString(R.string.no_network_image_desc)
    Glide.with(this)
            .load(R.drawable.ic_no_web_view_illustration)
            .into(mErrorImage)

    val enableButton = findViewById<Button>(R.id.error_handler_btn)
    enableButton.setOnClickListener { openGooglePlayStore() }
    enableButton.text = resources.getString(R.string.no_package_btn_text)

    val reloadText = findViewById<TextView>(R.id.no_network_reload)
    reloadText.setOnClickListener { reloadApplication() }

    val errorHeadingText = findViewById<TextView>(R.id.error_heading)
    val errorSubheadingText = findViewById<TextView>(R.id.error_subheading)
    errorHeadingText.text = resources.getString(R.string.no_package_heading_text)
    errorSubheadingText.text = resources.getString(R.string.no_package_subheading_text)
}

/**
 * This is a onClickListener Handler that
 * reloads the application when the user
 * clicks on it.
 * It starts the activity again from
 */
private fun reloadApplication() {
    val intent = Intent(this, SplashScreen::class.java)
    startActivity(intent)
    finish()
}

private fun openGooglePlayStore() {
    // you can also use BuildConfig.APPLICATION_ID
    val appId = "com.google.android.webview"
    val rateIntent = Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=$appId"))
    var marketFound = false
    // find all applications able to handle our rateIntent
    val otherApps = packageManager
            .queryIntentActivities(rateIntent, 0)
    for (otherApp in otherApps) { // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName
                == "com.android.vending") {
            val otherAppActivity = otherApp.activityInfo
            val componentName = ComponentName(
                    otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name
            )
            // make sure it does NOT open in the stack of your activity
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            // task reparenting if needed
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
            // if the Google Play was already open in a search result
            //  this make sure it still go to the app page you requested
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            // this make sure only the Google Play app is allowed to
            // intercept the intent
            rateIntent.component = componentName
            startActivity(rateIntent)
            marketFound = true
            break
        }
    }
    // if GP not present on device, open web browser
    if (!marketFound) {
        val webIntent = Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=$appId"))
        startActivity(webIntent)
    }
}
Dhruvam Sharma
  • 1,661
  • 14
  • 22
1

This crash problem happens on Android 5.0 and 5.1 Lollipop (API 21/22), when using version 1.1.0 of some AndroidX Jetpack libraries:

implementation "androidx.appcompat:appcompat:1.1.0"

or

implementation "androidx.preference:preference:1.1.0"

It happens when your device does not have Google Chrome browser or "Android System WebView" installed from the Google Play Store. Some stock emulators that don't have Google Play Services installed will therefore experience this problem.

How to Solve

Updating to a higher AndroidX version, like 1.2.0-alpha03 will fix it, as mentioned here:

Error inflating class android.webkit.WebView Crash on Lollipop when opening PDF

implementation "androidx.appcompat:appcompat:1.2.0-alpha03"

Or use a custom fix in AppCompatActivity.applyOverrideConfiguration(). See: android.view.InflateException Error inflating class android.webkit.WebView

See also:

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
  • thanks this works, seems like there were some libraries which were missing in implementation "androidx.appcompat:appcompat:1.1.0" but after replacing it with updated version implementation "androidx.appcompat:appcompat:1.2.0-alpha03" solves my issue. – Divyanshu Kumar Apr 15 '20 at 06:51
0

I had same problem and i solved this problem by changing its theme in manifest

Eleg Uni
  • 21
  • 1
  • 3
0

It seems that something strange occurred when the app was inflating the WebView, could be whatever. For the NameNotFoundException: com.google.android.webview problem with the Google packages

 if(getPackageManager().hasSystemFeature("android.software.webview") == true && isPackageExisted("com.google.android.webview")) {
                if (Constant.isNetworkConnected(LoginActivity.this)) {

                     //Your Intent 
                } else {
                    Toast.makeText(getApplicationContext(), resources.getString(R.string.internet_error), Toast.LENGTH_SHORT).show();
                }
            }else
                {
                    Constant.showDialog(LoginActivity.this,"Please install the webview");
                }
        }

//Make method for package check

public boolean isPackageExisted(String targetPackage){
    List<ApplicationInfo> packages;
    PackageManager pm;

    pm = getPackageManager();
    packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) {
        if(packageInfo.packageName.equals(targetPackage))
            return true;
    }
    return false;
}
Shaikh Mohib
  • 278
  • 3
  • 11
0

I was testing my app in android emulator and i got this issue and it is because in my android emulator google chrome was not installed and fixed by installing google chrome


Error inflating class android.webkit.WebView

Midhilaj
  • 4,905
  • 9
  • 45
  • 88