Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameNotFoundException webview

It's likely that this is happening in the very short time frame immediately after Lollipop's Android System WebView application updates.

I'd seen this error in the Google Play Dev Console, but also had never been able to reproduce it on my Nexus 5, regardless of how much I really tried to stop my app from having access to the Android System WebView app:

java.lang.RuntimeException: Unable to create application com.uninteresting.app.name:
    android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview

Then we got word that our app was consistently crashing with the above message on some devices immediately after the System WebView app updates, so I tested that. Still no results, the vanilla Nexus 5 refused to crash our app! So I tried other phones from other manufacturers (roughly 75% of our reports are from Samsung Galaxy devices) and suddenly we were crashing consistently. My testing methodology:

  1. Open your app, make sure a WebView is showing.
  2. Open Play Store, navigate to "My Apps," and bring up "Android System WebView." Uninstall updates. This shouldn't crash you, but you should see your app force-restart.
  3. Open your app back up and let it recover from the restart.
  4. Go back into the Play Store and update Android System WebView.
  5. Re-focus your app during the update process. Now, if you're on an affected device, it should crash. If not, your app will just be pushed to the background and quietly restarted.

A few little caveats with what I've said so far:

  • Our app makes the mistake of starting up a WebView extremely early, hence why we get "unable to create application" in our crash message. The user doesn't even have to be looking at our app for it to crash. I doubt this applies to you, but if your app attempts to restart its activity containing a WebView during this scenario, that would explain it.
  • 100% of our reports are from 5.0 devices, I have no earthly clue how this could occur on anything below Lollipop.
  • We do see reports of Nexus 4 and Nexus 5 with this error, so I don't know why I can't reproduce it on those devices. Might be a separate root cause, but I need to look further into that.

In short, I don't immediately think you're doing anything incorrect with ProGuard or your JavascriptInterface. I'm leaning very strongly toward blaming the firmware as the root cause of the majority of reports, resulting in what should be a smooth update process becoming one that instead causes some apps to outright crash.

Edit: I ran a few more tests and it turns out that all the devices that didn't crash are 5.0 or 5.0.1, while all the devices that did crash were 5.0.2, so I can't comfortably point my finger at OEMs anymore.


Easy way to check with androidx.webkit library:

dependencies {
    ...
    implementation 'androidx.webkit:webkit:1.4.0'
}

Use WebViewCompat.getCurrentWebViewPackage method before (for example, ads):

val webViewPackageInfo = WebViewCompat.getCurrentWebViewPackage(appContext)
Timber.d("📦 web view package info: %s", webViewPackageInfo?.toString())
val isWebViewPackageAvailable = webViewPackageInfo != null
prepareWithAds(canPlayAds = isWebViewPackageAvailable)

Steps for reproduce:

  1. Disable or delete system WebView service
  • Disable: Go to system settings menu -> Apps -> Android System WebView -> Disable
  • Delete:
adb root
adb shell pm uninstall -k --user 0 com.google.android.webview
  1. Open smth WebView
  2. Then WebView will crashed if package unavailable:

E/WebViewFactory: Chromium WebView package does not exist android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed