react-native-webview: Failed to load WebView provider: No WebView installed android.webkit.WebViewFactory.getProviderClass

Good day! Every week my app crashes in the production mode on android devices. Basically it is happening on Xiaomi, Samsung, LGE phones with Android 10.

Bug description: The app crashes in the production mode with an exception: Caused by android.webkit.WebViewFactory$MissingWebViewPackageException Failed to load WebView provider: No WebView installed

To Reproduce: I don’t have steps. Just a crash report from crashlytics.

Caused by android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
       at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:339)
       at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:402)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:252)
       at android.webkit.CookieManager.getInstance(CookieManager.java:47)
       at com.facebook.react.modules.network.ForwardingCookieHandler.getCookieManager(ForwardingCookieHandler.java:180)
       at com.facebook.react.modules.network.ForwardingCookieHandler.get(ForwardingCookieHandler.java:58)
       at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:61)
       at com.facebook.react.modules.network.ReactCookieJarContainer.loadForRequest(ReactCookieJarContainer.java:44)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
       at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
       at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)

Expected behavior: The app is not crashes.

Screenshots/Videos: No have, because it is happening in the production mode. I can not catch the crash in the develop mode. I checked many times.

Environment:

  • OS: Android
  • OS version: Android 10
  • react-native version: 0.62.0
  • react-native-webview version: 9.2.2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 27 (2 by maintainers)

Most upvoted comments

I am not sure this issue related with react-native repository. There is a PR to resolve same issue in react-native. If you want to check, here is link to PR I found a way to reproduce this issue and commented on that PR.

After Disable Android System WebView system app, you can get AndroidRuntimeException exception with MissingWebViewPackageException message.

Not stale

I see it on LG K31 and K51. Not much details, just a trace in crashlytics.

I also have some doubts if this is really a ReactNativeWebView issue, or maybe ReactNative in general. Look at the top of stack trace:

Caused by android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
   at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:339)
   at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:402)
   at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:252)
   at android.webkit.CookieManager.getInstance(CookieManager.java:47)
   at com.facebook.react.modules.network.ForwardingCookieHandler.getCookieManager(ForwardingCookieHandler.java:180)

It’s not web view creation, it’s merely the cookie handler. Working hypothesis: ReactNative cookie handling (used for generic network access) has a dependency on system web view in Android. When this web view isn’t available (which isn’t guaranteed, according to stackoverflow in some previous comment), then ReactNative crashes. If I’m right, then https://github.com/facebook/react-native/issues/18322 needs to be reopened.

My instinct tells me it’s a samsung only problem… I’m curious if other people can report the devices which have this problem

Happened twice yesterday

Both times on Android 10 samsung SM-A205W device

Never had this problem while testing in debug mode…

The check implemented in PR https://github.com/facebook/react-native/pull/29089 is flawed as the exception class name depends on the OS version as well as the OEM. In OxygenOS running android 11, it comes out as RuntimeException and the check fails and hence the crash occurs again. There is a simple fix to that as well, by checking the message instead of the exception class. Here is the snippet:

  private @Nullable CookieManager getCookieManager() {
    if (mCookieManager == null) {
      possiblyWorkaroundSyncManager(mContext);
      try {
        mCookieManager = CookieManager.getInstance();
      } catch (IllegalArgumentException ex) {
        // https://bugs.chromium.org/p/chromium/issues/detail?id=559720
        return null;
      } catch (Exception exception) {
        String message = exception.getMessage();
        // We cannot catch MissingWebViewPackageException as it is in a private / system API
        // class. This validates the exception's message to ensure we are only handling this
        // specific exception.
        // The exception class doesn't always contain the correct name as it depends on the OEM
        // and OS version. It is better to check the message for clues regarding the exception
        // as that is somewhat consistent across OEMs.
        // https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebViewFactory.java#348
        if (message!=null &&
                (message.contains("MissingWebViewPackageException")
                  || message.contains("No WebView installed") || message.contains("WebView))) {
          return null;
        } else {
          throw exception;
        }
      }

      if (USES_LEGACY_STORE) {
        mCookieManager.removeExpiredCookie();
      }
    }

    return mCookieManager;
  }

NOTE: The code seems to have changed slightly for the latest version of React Native 0.67.2. However the check used in that code is still incorrect.

The correct check is still the same used in the snippet:

if (message!=null &&
                (message.contains("MissingWebViewPackageException")
                  || message.contains("No WebView installed") || message.contains("WebView))) {
          return null;
        } else {
          throw exception;
        }

Still happens

I’ve figured it out. The user trying to install the app with this library needs to install “Android System Webview” by Google from Play Store. This library doesn’t have a mechanism to check whether the user has installed “Android System Webview” or not.

Android System Webview in Play Store

Is it?

still happens