react-native-webview / react-native-webview

React Native Cross-Platform WebView
https://github.com/react-native-community/discussions-and-proposals/pull/3
MIT License
6.49k stars 2.99k forks source link

Failed to load WebView provider: No WebView installed android.webkit.WebViewFactory.getProviderClass #1624

Closed jocoders closed 3 years ago

jocoders commented 4 years ago

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:

cristianoccazinsp commented 3 years ago

I'm seeing the same crash. Related info:

https://github.com/react-native-webview/react-native-webview/issues/14

https://stackoverflow.com/questions/43917214/android-how-to-check-if-webview-is-available/43925989#43925989

https://stackoverflow.com/questions/46048912/android-failed-to-load-webview-provider-no-webview-installed/46266199

cristianoccazinsp commented 3 years ago

My stack trace as well:

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

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

Device:
moto g(7) play

OS: Android 10

github-actions[bot] commented 3 years ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

rosskhanas commented 3 years ago

Not stale

yanel777 commented 3 years ago

still happens

StevenWonder commented 3 years ago

Happened twice yesterday

Both times on Android 10 samsung SM-A205W device

Never had this problem while testing in debug mode...

StevenWonder commented 3 years ago

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

tszajna0 commented 3 years ago

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.

mardikarifqi commented 3 years ago

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?

RodolfoGS commented 3 years ago

I have the same issue, any suggestion? I've a lot of crashes like this

Fatal Exception: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
       at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:435)
       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)
Bardiamist commented 3 years ago

device: SM-J400F model id: QP1A.190711.020 name: Samsung galaxy j4 environment: prod hermes: true level: fatal os: Android 10 os.rooted: no

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.c.getCookieManager
    at com.facebook.react.modules.network.c.get
    at okhttp3.JavaNetCookieJar.loadForRequest
    at com.facebook.react.modules.network.l.loadForRequest
    at okhttp3.internal.http.BridgeInterceptor.intercept
    at okhttp3.internal.http.RealInterceptorChain.proceed
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept
    at okhttp3.internal.http.RealInterceptorChain.proceed
    at okhttp3.internal.http.RealInterceptorChain.proceed
    at okhttp3.RealCall.getResponseWithInterceptorChain
    at okhttp3.RealCall$AsyncCall.execute
    at okhttp3.internal.NamedRunnable.run
    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)
android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
    at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:435)
    at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:252)
    at android.webkit.CookieManager.getInstance(CookieManager.java:47)
    at com.facebook.react.modules.network.c.getCookieManager
    at com.facebook.react.modules.network.c.get
    at okhttp3.JavaNetCookieJar.loadForRequest
    at com.facebook.react.modules.network.l.loadForRequest
    at okhttp3.internal.http.BridgeInterceptor.intercept
    at okhttp3.internal.http.RealInterceptorChain.proceed
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept
    at okhttp3.internal.http.RealInterceptorChain.proceed
    at okhttp3.internal.http.RealInterceptorChain.proceed
    at okhttp3.RealCall.getResponseWithInterceptorChain
    at okhttp3.RealCall$AsyncCall.execute
    at okhttp3.internal.NamedRunnable.run
    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)
9Hyeonwoo commented 3 years ago

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.

RodolfoGS commented 3 years ago

@9Hyeonwoo you are right, it's a react-native bug. I could reproduce the crash disabling Android System WebView

github-actions[bot] commented 3 years ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

MuhammadUsman786786 commented 3 years ago

Still happens

KunalFarmah98 commented 2 years ago

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;
        }
androideveloper commented 2 years ago

Hey @KunalFarmah98 Where you able to fix it? We also have a similar issue, the exception is different ("android.util.AndroidRuntimeException") and the provided check fails

KunalFarmah98 commented 2 years ago

Hey @KunalFarmah98 Where you able to fix it? We also have a similar issue, the exception is different ("android.util.AndroidRuntimeException") and the provided check fails

@androideveloper I also considered that case and added an additional check for message contains("WebView").

I have updated my comment as well. In our app we are directly checking for WebView in the error message. But I had made the check slightly less generic to check for 2 other cases as well as I saw 2 different types of messages in the same crash in our app.

androideveloper commented 2 years ago

Do you load this as a patch to RN? And did you report it somewhere? I also added a comment about it here https://github.com/facebook/react-native/pull/29089/files#r801504483

KunalFarmah98 commented 2 years ago

Do you load this as a patch to RN? And did you report it somewhere? I also added a comment about it here https://github.com/facebook/react-native/pull/29089/files#r801504483

Well you can either add it as a patch and build react native from source i.e via ReactAndroid using NDK or create a fork repo and use that as the react native source by pushing modified artifacts to it and fetching them in the node_modules.

You can find the steps here: https://github.com/facebook/react-native/wiki/Building-from-source

Only adding a patch won't work because react-native is fetched as an artifact whenever project is synched and the changes are lost.

Many people have reported it but they are not ready to merge the changes for some reason.

DamarHardy commented 2 years ago

What do you think the impact is if we return null for every exception rather than do this checking ? @KunalFarmah98

KunalFarmah98 commented 2 years ago

What do you think the impact is if we return null for every exception rather than do this checking ? @KunalFarmah98

If you are not getting any other exceptions from this class, it won't be an issue but checking for WebView in the message is also sufficient. Its working in our app with that check and a few internal checks using Webkit to check for webview package before loading a WebView or it would be an inflate exception caused by a ClassNotFound Exception.

I also raised a PR for this crash https://github.com/facebook/react-native/pull/33088 It has a slightly less generic check in it as suggested by them but a simple check for WebView in the message would be enough.

DamarHardy commented 2 years ago

I see, just wondering why the logic has option to throw exception at the first place while we can directly return null @KunalFarmah98

KunalFarmah98 commented 2 years ago

I see, just wondering why the logic has option to throw exception at the first place while we can directly return null @KunalFarmah98

Its there to cater for other exceptions that might be important for the developer to know. The only thing is that the exception for webview isn't an accessible class and different OEMs throw different exceptions for the same case. Hence the check for message is required while throwing any other exception that comes

sebas21 commented 1 year ago

what is the solution of this bug??

android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:435) at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:252) at android.webkit.CookieManager.getInstance(CookieManager.java:50) at com.facebook.react.modules.network.c.getCookieManager(Unknown Source:10) at com.facebook.react.modules.network.c.get(Unknown Source:0) at m0.x.c(Unknown Source:15) at com.facebook.react.modules.network.l.c(Unknown Source:4) at m0.k0.h.a.a(Unknown Source:130) at m0.k0.h.g.a(Unknown Source:166) at m0.k0.h.j.a(Unknown Source:34) at m0.k0.h.g.a(Unknown Source:166) at j.f.a.a.h.a(Unknown Source:12) at m0.k0.h.g.a(Unknown Source:166) at m0.k0.g.e.t(Unknown Source:113) at m0.k0.g.e$a.run(Unknown Source:51) 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:923) 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:50) at com.facebook.react.modules.network.c.getCookieManager(Unknown Source:10) at com.facebook.react.modules.network.c.get(Unknown Source:0) at m0.x.c(Unknown Source:15) at com.facebook.react.modules.network.l.c(Unknown Source:4) at m0.k0.h.a.a(Unknown Source:130) at m0.k0.h.g.a(Unknown Source:166) at m0.k0.h.j.a(Unknown Source:34) at m0.k0.h.g.a(Unknown Source:166) at j.f.a.a.h.a(Unknown Source:12) at m0.k0.h.g.a(Unknown Source:166) at m0.k0.g.e.t(Unknown Source:113) at m0.k0.g.e$a.run(Unknown Source:51) 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:923)

Symbolication information

Symbol file exist: false Symbolication successful: false

image
iphonic commented 5 months ago

Still happening in 2024

Fatal Exception: android.util.AndroidRuntimeException android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed

Fatal Exception: android.util.AndroidRuntimeException: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:382)
       at android.webkit.CookieManager.getInstance(CookieManager.java:50)
       at com.facebook.react.modules.network.ForwardingCookieHandler.getCookieManager(ForwardingCookieHandler.java:10)
       at com.facebook.react.modules.network.ForwardingCookieHandler.get(ForwardingCookieHandler.java)
       at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:15)
       at com.facebook.react.modules.network.ReactCookieJarContainer.loadForRequest(ReactCookieJarContainer.java:4)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:130)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:166)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:34)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:166)
       at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.java:113)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.java:51)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)
JoseVov commented 4 months ago

This is happening to me on Old Android devices. Is there any table with the android versions supported?