当前位置: 首页 > 知识库问答 >
问题:

NameNotFoundException webview

孟子墨
2023-03-14

我从Crashlytics收到错误,表明一些设备丢失了com.google.android.webview.这怎么可能?

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

我的MyWebView看起来像这样:

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有关。有什么想法吗?

编辑:从grepcode中,我找到了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);
        }
    }

共有1个答案

易阳云
2023-03-14

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

我在谷歌Playhtml" target="_blank">开发者控制台中看到过这个错误,但也从未在我的Nexus 5上重现过,无论我多么努力地阻止我的应用程序访问Android系统WebView应用程序:

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

然后我们得到消息,我们的应用程序在系统WebView应用程序更新后立即在某些设备上持续崩溃,所以我测试了一下。仍然没有结果,香草Nexus 5拒绝崩溃我们的应用程序!所以我尝试了其他制造商的其他手机(我们大约75%的报告来自三星Galaxy设备),突然我们一致崩溃。我的测试方法论:

  1. 打开应用程序,确保显示网络视图

关于我到目前为止所说的几点注意事项:

  • 我们的应用程序犯了一个非常早启动WebView的错误,因此我们在崩溃消息中得到“无法创建应用程序”。用户甚至不必查看我们的应用程序就会崩溃。我怀疑这适用于您,但如果您的应用程序在此场景中尝试重新启动其包含WebView的活动,那就可以解释它。
  • 我们100%的报告来自5.0设备,我不知道这是如何发生在Lollipop以下的任何东西上的。
  • 我们确实看到Nexus 4和Nexus 5有此错误的报告,所以我不知道为什么我不能在这些设备上重现它。可能是单独的根本原因,但我需要进一步研究。

简而言之,我不会立即认为您对ProGuard或JavascriptInterface做了任何不正确的事情。我强烈倾向于将固件作为大多数报告的根本原因,这导致了本应平滑的更新过程变成了导致一些应用程序彻底崩溃的过程。

编辑:我又做了一些测试,结果发现所有没有崩溃的设备都是5.0或5.0.1,而所有崩溃的设备都是5.0.2,所以我再也不能轻易地把手指指向OEM了。

 类似资料:

相关问答

相关文章

相关阅读