android Failed to load WebView provider: No WebView installed

前端 未结 4 2077
甜味超标
甜味超标 2020-12-05 18:18

Recently, we\'ve started seeing this new entry in our crashlytics which says that android can\'t find the webview package on the device.

Here\'s the full stacktrace

相关标签:
4条回答
  • 2020-12-05 18:41

    According to the TextView's sourceCode

    if (mAutoLinkMask != 0) {
        ...
        if (Linkify.addLinks(s2, mAutoLinkMask)) {
            ...
        }
    }
    

    The textview with android:autoLink property will call Linkify.addLinks (reaches the method of WebView finally) and cause the crash.

    So, we can remove the android:autoLink property and realize with other way to fix the problem.

    0 讨论(0)
  • 2020-12-05 18:45

    I figured out a probable problem here. As we know that webview has been shipping as a separate app from android 5.0, it may be the case that at the time my view is being inflated, the webview package is being updated by the os and therefore it can't find the webview pacakge for those few moments. I know it's a very borderline case but

    • as I can see, the crash is happening on only >= 5.0 devices which support this hypothesis
    • it's very hard to believe that all such devices don't have webview installed. As a matter of fact, I tried uninstalling the system and chrome packages from my device but still the app doesn't crash.

    So here's what I did (hacky solution but prevents crashes):

    try {
            // the inflating code that's causing the crash 
    
        } catch (Exception e) {
            if (e.getMessage() != null && e.getMessage().contains("webview")) {
                // If the system failed to inflate this view because of the WebView (which could
                // be one of several types of exceptions), it likely means that the system WebView
                // is either not present (unlikely) OR in the process of being updated (also unlikely).
                // It's unlikely but we have been receiving a lot of crashes.
                // In this case, show the user a message and finish the activity
            }
        }
    

    Basically nothing but handling that exception. No rocket science there.

    0 讨论(0)
  • 2020-12-05 19:03

    Please refer to this issue.

    Workaround

    try {
        super.setText(spannableStringBuilder, type);
    } catch (Exception e) {
        // WebView is not installed in some devices by default, Linkify.MAP_ADDRESSES causes the exception
        if (e.getMessage().contains("webview")){
            setAutoLinkMask(Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS);
        }
        super.setText(spannableStringBuilder, type);
    }
    
    0 讨论(0)
  • 2020-12-05 19:04

    My exception is

    android.webkit.WebViewFactory$MissingWebViewPackageException
    
    Failed to load WebView provider: No WebView installed
    

    detail stack is:

    java.lang.RuntimeException:Unable to start activity ComponentInfo{cn.trinea.android.developertools/a.a.aa}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class a.a.ab
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
    ......
    android.webkit.WebViewFactory$MissingWebViewPackageException:Failed to load WebView provider: No WebView installed
    android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:270)
    android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:330)
    android.webkit.WebViewFactory.getProvider(WebViewFactory.java:194)
    android.webkit.WebView.getFactory(WebView.java:2325)
    android.webkit.WebView.ensureProviderCreated(WebView.java:2320)
     android.webkit.WebView.setOverScrollMode(WebView.java:2379)
     android.view.View.<init>(View.java:4023)
     android.view.View.<init>(View.java:4146)
     android.view.ViewGroup.<init>(ViewGroup.java:579)
     android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
     android.webkit.WebView.<init>(WebView.java:627)
     android.webkit.WebView.<init>(WebView.java:572)
     android.webkit.WebView.<init>(WebView.java:555)
     android.webkit.WebView.<init>(WebView.java:542)
    

    solution is

    public class MyWebView extends WebView {
    
        @Override
        public void setOverScrollMode(int mode) {
            try {
                super.setOverScrollMode(mode);
            } catch (Exception e) {
                if (e.getMessage() != null && e.getMessage().contains("Failed to load WebView provider: No WebView installed")) {
                    e.printStackTrace();
                } else {
                    throw e;
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题