NameNotFoundException 网页视图 [英] NameNotFoundException webview

查看:21
本文介绍了NameNotFoundException 网页视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Crashlytics 收到错误消息,表明某些设备缺少 com.google.android.webview.这怎么可能?

I am getting errors from Crashlytics that indicates that some devices are missing com.google.android.webview. How is that even possible?

java.lang.RuntimeException: Unable to start activity   ComponentInfo{com.myapp.app/com.myapp.ReaderActivity}: android.view.InflateException: Binary XML file line #29: Error inflating class com.myapp.MyWebView
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       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:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class com.myapp.MyWebView
       at android.view.LayoutInflater.createView(LayoutInflater.java:633)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(SourceFile:206)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(SourceFile:20)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(SourceFile:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(SourceFile:228)
       at android.support.v7.app.ActionBarActivity.setContentView(SourceFile:102)
       at com.myapp.ReaderActivity.onCreate(SourceFile:120)
       at android.app.Activity.performCreate(Activity.java:5933)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       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:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
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:607)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(SourceFile:206)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(SourceFile:20)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(SourceFile:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(SourceFile:228)
       at android.support.v7.app.ActionBarActivity.setContentView(SourceFile:102)
       at com.myapp.ReaderActivity.onCreate(SourceFile:120)
       at android.app.Activity.performCreate(Activity.java:5933)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       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:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:161)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
       at android.webkit.WebView.getFactory(WebView.java:2185)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2180)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2239)
       at android.view.View.(View.java:3581)
       at android.view.View.(View.java:3675)
       at android.view.ViewGroup.(ViewGroup.java:491)
       at android.widget.AbsoluteLayout.(AbsoluteLayout.java:55)
       at android.webkit.WebView.(WebView.java:538)
       at android.webkit.WebView.(WebView.java:483)
       at android.webkit.WebView.(WebView.java:466)
       at android.webkit.WebView.(WebView.java:453)
       at com.myapp.MyWebView.(SourceFile:31)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:607)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(SourceFile:206)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(SourceFile:20)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(SourceFile:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(SourceFile:228)
       at android.support.v7.app.ActionBarActivity.setContentView(SourceFile:102)
       at com.myapp.ReaderActivity.onCreate(SourceFile:120)
       at android.app.Activity.performCreate(Activity.java:5933)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       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:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:114)
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:133)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
       at android.webkit.WebView.getFactory(WebView.java:2185)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2180)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2239)
       at android.view.View.(View.java:3581)
       at android.view.View.(View.java:3675)
       at android.view.ViewGroup.(ViewGroup.java:491)
       at android.widget.AbsoluteLayout.(AbsoluteLayout.java:55)
       at android.webkit.WebView.(WebView.java:538)
       at android.webkit.WebView.(WebView.java:483)
       at android.webkit.WebView.(WebView.java:466)
       at android.webkit.WebView.(WebView.java:453)
       at com.myapp.MyWebView.(SourceFile:31)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:607)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(SourceFile:206)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(SourceFile:20)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(SourceFile:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(SourceFile:228)
       at android.support.v7.app.ActionBarActivity.setContentView(SourceFile:102)
       at com.myapp.ReaderActivity.onCreate(SourceFile:120)
       at android.app.Activity.performCreate(Activity.java:5933)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       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:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

而且它仅来自运行 Lollipop 的设备.我已在 Nexus 5 上对其进行了测试,但无法重现该错误.我正在使用 proguard

And it is only from devices running Lollipop. I have tested it on my Nexus 5, but I can not reproduce the error. I am using proguard

我的 MyWebView 如下所示:

My MyWebView looks like this:

public class MyWebView extends WebView {

    public static final String tag = MyWebView.class.getName();
    private HtmlJSInterfaceNew js;

    public MyWebView(Context context) {
        super(context);
        gd = new GestureDetector(context, sogl);
        init();
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        gd = new GestureDetector(context, sogl);
        init();
    }

    public MyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        gd = new GestureDetector(context, sogl);
        init();
    }

    @SuppressLint("NewApi")
    private void init() {
        setPadding(0, 0, 0, 0);
        MyWebViewClient myWebViewClient = new MyWebViewClient();        
        this.setWebViewClient(myWebViewClient);
        setWebChromeClient(new MyWebChromeClient());
        if(!isInEditMode())
        {
            getSettings().setAllowFileAccess(true);
            getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
            getSettings().setJavaScriptEnabled(true);
            WebSettings webSettings = getSettings();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                webSettings.setAllowContentAccess(false);
            }

            webSettings.setUseWideViewPort(true);


        }


    }
    public void addMyJavascriptInterface(HtmlJSInterfaceNew htmlJSInterface, String string) {
        js = htmlJSInterface;
        addJavascriptInterface(htmlJSInterface, string);
    }

    public class MyWebChromeClient extends WebChromeClient
    {
        public void onProgressChanged(WebView view, int progress) {
        }
    }
}

最根本的原因是:

android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:161)

所以我认为这可能与 proguard 以及 JavascriptInterface 有关.有什么想法吗?

So I am thinking it might have something to do with proguard and maybe the JavascriptInterface. Any ideas?

从 grepcode 我找到了 getFactoryClass 方法:

from grepcode I have found the method getFactoryClass:

private static Class<WebViewFactoryProvider> getFactoryClass() throws ClassNotFoundException {
        Application initialApplication = AppGlobals.getInitialApplication();
        try {
            // First fetch the package info so we can log the webview package version.
            String packageName = getWebViewPackageName();
            sPackageInfo = initialApplication.getPackageManager().getPackageInfo(packageName, 0);
            Log.i(LOGTAG, "Loading " + packageName + " version " + sPackageInfo.versionName +
                          " (code " + sPackageInfo.versionCode + ")");

            // Construct a package context to load the Java code into the current app.
            Context webViewContext = initialApplication.createPackageContext(packageName,
                    Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
            initialApplication.getAssets().addAssetPath(
                    webViewContext.getApplicationInfo().sourceDir);
            ClassLoader clazzLoader = webViewContext.getClassLoader();
            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
            try {
                return (Class<WebViewFactoryProvider>) Class.forName(CHROMIUM_WEBVIEW_FACTORY, true,
                                                                     clazzLoader);
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            }
        } catch (PackageManager.NameNotFoundException e) {
            // If the package doesn't exist, then try loading the null WebView instead.
            // If that succeeds, then this is a device without WebView support; if it fails then
            // swallow the failure, complain that the real WebView is missing and rethrow the
            // original exception.
            try {
                return (Class<WebViewFactoryProvider>) Class.forName(NULL_WEBVIEW_FACTORY);
            } catch (ClassNotFoundException e2) {
                // Ignore.
            }
            Log.e(LOGTAG, "Chromium WebView package does not exist", e);
            throw new AndroidRuntimeException(e);
        }
    }

推荐答案

这很可能发生在 Lollipop 的 Android System WebView 应用程序更新后的很短的时间内.

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

我在 Google Play Dev Console 中看到过这个错误,但也从来没有能够在我的 Nexus 5 上重现它,不管我有多少真的试图阻止我的应用程序访问 Android 系统 WebView 应用程序:

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

然后我们得知我们的应用程序在 System WebView 应用程序更新后立即在某些设备上始终崩溃并显示上述消息,因此我对此进行了测试.仍然没有结果,香草 Nexus 5 拒绝使我们的应用程序崩溃!所以我尝试了其他制造商的其他手机(我们的报告中大约 75% 来自三星 Galaxy 设备),突然间我们一直崩溃.我的测试方法:

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. 打开您的应用,确保 WebView 正在显示.
  2. 打开 Play 商店,导航到我的应用",然后调出Android 系统WebView."卸载更新.这不应该让你崩溃,但你应该会看到您的应用强制重启.
  3. 打开您的应用备份,让它从重启中恢复.
  4. 返回 Play 商店并更新 Android System WebView.
  5. 在更新过程中重新聚焦您的应用.现在,如果你在受影响的设备,它应该崩溃.如果没有,您的应用程序将只是推到后台,悄悄重启.

对我目前所说的内容提出几点警告:

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

  • 我们的应用犯了一个错误,很早启动了一个 WebView,这就是为什么我们在崩溃消息中得到无法创建应用程序"的原因.用户甚至不必看着我们的应用程序就会崩溃.我怀疑这是否适用于您,但如果您的应用在这种情况下尝试重新启动其包含 WebView 的活动,那就可以解释了.
  • 我们 100% 的报告来自 5.0 设备,我不知道这会发生在 Lollipop 以下的任何设备上.
  • 我们确实看到 Nexus 4 和 Nexus 5 出现此错误的报告,所以我不知道为什么我无法在这些设备上重现它.可能是一个单独的根本原因,但我需要进一步研究.
  • 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.

简而言之,我不会立即认为您在使用 ProGuard 或您的 JavascriptInterface 时做错了任何事情.我非常倾向于将固件归咎于大多数报告的根本原因,导致本应平稳的更新过程变成了导致某些应用程序彻底崩溃的过程.

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.

我又进行了几次测试,结果发现所有没有崩溃的设备都是 5.0 或 5.0.1,而所有崩溃的设备都是 5.0.2,所以我不能再轻松地指责原始设备制造商了.

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.

这篇关于NameNotFoundException 网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆