web视图的NameNotFoundException [英] NameNotFoundException webview

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

问题描述

我收到来自Crashlytics错误,指示缺少某些设备的com.google.android.webview。这怎么可能呢?

 了java.lang.RuntimeException:无法启动活动ComponentInfo {com.myapp.app / com.myapp.ReaderActivity}:android.view.InflateException:二进制XML文件中的行#29:错误充气类com.myapp.MyWebView
       在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
       在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
       在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
       在android.os.Handler.dispatchMessage(Handler.java:102)
       在android.os.Looper.loop(Looper.java:135)
       在android.app.ActivityThread.main(ActivityThread.java:5221)
       在java.lang.reflect.Method.invoke(Method.java)
       在java.lang.reflect.Method.invoke(Method.java:372)
       在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
致:android.view.InflateException:二进制XML文件中的行#29:错误充气类com.myapp.MyWebView
       在android.view.LayoutInflater.createView(LayoutInflater.java:633)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(的SourceFile:206)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access $ 000(的SourceFile:20)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       在android.view.LayoutInflater $ FactoryMerger.onCreateView(LayoutInflater.java:177)
       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(的SourceFile:60)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       在android.support.v7.app.ActionBarActivityDelegateBase.setContentView(的SourceFile:228)
       在android.support.v7.app.ActionBarActivity.setContentView(的SourceFile:102)
       在com.myapp.ReaderActivity.onCreate(的SourceFile:120)
       在android.app.Activity.performCreate(Activity.java:5933)
       在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
       在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
       在android.os.Handler.dispatchMessage(Handler.java:102)
       在android.os.Looper.loop(Looper.java:135)
       在android.app.ActivityThread.main(ActivityThread.java:5221)
       在java.lang.reflect.Method.invoke(Method.java)
       在java.lang.reflect.Method.invoke(Method.java:372)
       在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
java.lang.reflect.InvocationTargetException:产生的原因
       在java.lang.reflect.Constructor.newInstance(Constructor.java)
       在java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       在android.view.LayoutInflater.createView(LayoutInflater.java:607)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(的SourceFile:206)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access $ 000(的SourceFile:20)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       在android.view.LayoutInflater $ FactoryMerger.onCreateView(LayoutInflater.java:177)
       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(的SourceFile:60)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       在android.support.v7.app.ActionBarActivityDelegateBase.setContentView(的SourceFile:228)
       在android.support.v7.app.ActionBarActivity.setContentView(的SourceFile:102)
       在com.myapp.ReaderActivity.onCreate(的SourceFile:120)
       在android.app.Activity.performCreate(Activity.java:5933)
       在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
       在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
       在android.os.Handler.dispatchMessage(Handler.java:102)
       在android.os.Looper.loop(Looper.java:135)
       在android.app.ActivityThread.main(ActivityThread.java:5221)
       在java.lang.reflect.Method.invoke(Method.java)
       在java.lang.reflect.Method.invoke(Method.java:372)
       在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
致:android.util.AndroidRuntimeException:android.content.pm.PackageManager $的NameNotFoundException:com.google.android.webview
       在android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:161)
       在android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
       在android.webkit.WebView.getFactory(WebView.java:2185)
       在android.webkit.WebView.ensureProviderCreated(WebView.java:2180)
       在android.webkit.WebView.setOverScrollMode(WebView.java:2239)
       在android.view.View(View.java:3581)
       在android.view.View(View.java:3675)
       在android.view.ViewGroup(ViewGroup.java:491)
       在android.widget.AbsoluteLayout(AbsoluteLayout.java:55)
       在android.webkit.WebView(WebView.java:538)
       在android.webkit.WebView(WebView.java:483)
       在android.webkit.WebView(WebView.java:466)
       在android.webkit.WebView(WebView.java:453)
       在com.myapp.MyWebView(的SourceFile:31)。
       在java.lang.reflect.Constructor.newInstance(Constructor.java)
       在java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       在android.view.LayoutInflater.createView(LayoutInflater.java:607)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(的SourceFile:206)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access $ 000(的SourceFile:20)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       在android.view.LayoutInflater $ FactoryMerger.onCreateView(LayoutInflater.java:177)
       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(的SourceFile:60)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       在android.support.v7.app.ActionBarActivityDelegateBase.setContentView(的SourceFile:228)
       在android.support.v7.app.ActionBarActivity.setContentView(的SourceFile:102)
       在com.myapp.ReaderActivity.onCreate(的SourceFile:120)
       在android.app.Activity.performCreate(Activity.java:5933)
       在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
       在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
       在android.os.Handler.dispatchMessage(Handler.java:102)
       在android.os.Looper.loop(Looper.java:135)
       在android.app.ActivityThread.main(ActivityThread.java:5221)
       在java.lang.reflect.Method.invoke(Method.java)
       在java.lang.reflect.Method.invoke(Method.java:372)
       在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
致:android.content.pm.PackageManager $的NameNotFoundException:com.google.android.webview
       在android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:114)
       在android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:133)
       在android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
       在android.webkit.WebView.getFactory(WebView.java:2185)
       在android.webkit.WebView.ensureProviderCreated(WebView.java:2180)
       在android.webkit.WebView.setOverScrollMode(WebView.java:2239)
       在android.view.View(View.java:3581)
       在android.view.View(View.java:3675)
       在android.view.ViewGroup(ViewGroup.java:491)
       在android.widget.AbsoluteLayout(AbsoluteLayout.java:55)
       在android.webkit.WebView(WebView.java:538)
       在android.webkit.WebView(WebView.java:483)
       在android.webkit.WebView(WebView.java:466)
       在android.webkit.WebView(WebView.java:453)
       在com.myapp.MyWebView(的SourceFile:31)。
       在java.lang.reflect.Constructor.newInstance(Constructor.java)
       在java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       在android.view.LayoutInflater.createView(LayoutInflater.java:607)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(的SourceFile:206)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access $ 000(的SourceFile:20)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(SourceFile:297)
       在android.view.LayoutInflater $ FactoryMerger.onCreateView(LayoutInflater.java:177)
       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       在uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(的SourceFile:60)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       在android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       在android.support.v7.app.ActionBarActivityDelegateBase.setContentView(的SourceFile:228)
       在android.support.v7.app.ActionBarActivity.setContentView(的SourceFile:102)
       在com.myapp.ReaderActivity.onCreate(的SourceFile:120)
       在android.app.Activity.performCreate(Activity.java:5933)
       在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
       在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
       在android.os.Handler.dispatchMessage(Handler.java:102)
       在android.os.Looper.loop(Looper.java:135)
       在android.app.ActivityThread.main(ActivityThread.java:5221)
       在java.lang.reflect.Method.invoke(Method.java)
       在java.lang.reflect.Method.invoke(Method.java:372)
       在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 

和它只是运行棒棒糖设备。我有我的的Nexus 5测试,但我无法重现的错误。我使用的ProGuard

我的MyWebView看起来是这样的:

 公共类MyWebView扩展的WebView {

    公共静态最终字符串变量= MyWebView.class.getName();
    私人HtmlJSInterfaceNew JS;

    公共MyWebView(上下文的背景下){
        超(上下文);
        GD =新GestureDetector(背景下,sogl);
        在里面();
    }

    公共MyWebView(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
        GD =新GestureDetector(背景下,sogl);
        在里面();
    }

    公共MyWebView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,defStyle);
        GD =新GestureDetector(背景下,sogl);
        在里面();
    }

    @燮pressLint(NewApi)
    私人无效的init(){
        setPadding(0,0,0,0);
        MyWebViewClient myWebViewClient =新MyWebViewClient();
        this.setWebViewClient(myWebViewClient);
        setWebChromeClient(新MyWebChromeClient());
        如果(!isInEditMode())
        {
            。的getSettings()setAllowFileAccess(真正的);
            。的getSettings()setJavaScriptCanOpenWindowsAutomatically(假);
            的getSettings()setJavaScriptEnabled(真)。
            WebSettings webSettings =的getSettings();

            如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.HONEYCOMB){
                webSettings.setAllowContentAccess(假);
            }

            webSettings.setUseWideViewPort(真正的);


        }


    }
    公共无效addMyJavascriptInterface(HtmlJSInterfaceNew htmlJSInterface,串串){
        JS = htmlJSInterface;
        addJavascriptInterface(htmlJSInterface,字符串);
    }

    公共类MyWebChromeClient扩展WebChromeClient
    {
        公共无效onProgressChanged(web视图来看,INT进度){
        }
    }
}
 

的根本原因最是:

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

所以,我想它可能是与ProGuard的,也许是JavascriptInterface。任何想法?

编辑: 从grep的code我已经找到了方法getFactoryClass:

 私有静态类< WebViewFactoryProvider> getFactoryClass()抛出ClassNotFoundException的{
        应用initialApplication = AppGlobals.getInitialApplication();
        尝试 {
            //首先取包信息,以便我们可以登录web视图包的版本。
            串的packageName = getWebViewPackageName();
            sPackageInfo = initialApplication.getPackageManager()getPackageInfo(的packageName,0)。
            Log.i(LOGTAG,加载+的packageName +版本+ sPackageInfo.versionName +
                          (code+ sPackageInfo.version code +));

            //构造一个包的上下文装载Java code到当前的应用程序。
            上下文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());
            尝试 {
                返程(类< WebViewFactoryProvider>)的Class.forName(CHROMIUM_WEBVIEW_FACTORY,真实,
                                                                     clazzLoader);
            } 最后 {
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            }
        }赶上(PackageManager.NameNotFoundException E){
            //如果包不存在,然后尝试加载空的WebView替代。
            //如果成功,那么这是没有的WebView支持装置;如果失败的话
            //吞下失败,抱怨说,真正的WebView丢失并重新抛出的
            //原始的异常。
            尝试 {
                返程(类< WebViewFactoryProvider>)的Class.forName(NULL_WEBVIEW_FACTORY);
            }赶上(ClassNotFoundException的E2){
                // 忽略。
            }
            Log.e(LOGTAG,铬的WebView包不存在,E);
            抛出新AndroidRuntimeException(E);
        }
    }
 

解决方案

这可能是因为这是棒棒堂的Andr​​oid系统的WebView应用程序更新后发生在很短的时间。

我看到了谷歌这个错误播放开发控制台,也从未能够重现它在我的Nexus 5,不管我到底有多大试图从有机会获得Android系统的WebView应用程序停止我的应用程序

 了java.lang.RuntimeException:无法创建应用程序com.uninteresting.app.name:
    android.util.AndroidRuntimeException:android.content.pm.PackageManager $的NameNotFoundException:com.google.android.webview
 

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

  1. 打开您的应用程序,确保一个的WebView是显示。
  2. 开启Play商店,点击我的应用,并带来了Android系统 的WebView。卸载更新。这应该不会崩溃,但是你 应该可以看到你的应用程序强制重启。
  3. 打开您的应用程序备份并让它从重启中恢复过来。
  4. 在返回到Play商店和更新Android系统的WebView。
  5. 在更新过程中重新集中你的应用程序。现在,如果你是在一个 受影响的设备,它应该崩溃。如果没有,你的应用程序将只是 被推到了后台悄悄地重新启动。

与我到目前为止已经说了几句小告诫:

  • 在我们的应用程序,使得启动一个web视图的的错误极早的,因此为什么我们得到无法创建应用程序我们崩溃的消息。用户甚至不必须看我们的应用程序为它崩溃。我怀疑这适用于你,但如果你的应用程序尝试重新启动此方案中包含的WebView其活性,这可以解释它。
  • 我们的报告
  • 100%都来自5.0的设备,我没有尘世的线索,这怎么会发生在以下棒棒糖什么。
  • 我们确实看到的Nexus 4和Nexus 5,此错误的报告,所以我不知道为什么我不能重现它在这些设备上。可能是一个独立的根本原因,但我需要进一步考虑的。

总之,我不要马上认为你正在做的事情不正确使用ProGuard或JavascriptInterface。我倾向于强烈朝指责固件多数报告的根本原因,造成什么应该是一个平滑的升级过程成为一个反而使一些应用程序,以彻底崩溃。

编辑:我跑了几个测试,事实证明,所有没有崩溃的设备是5.0或5.0.1,而所有没有崩溃的设备是5.0.2,所以我不能舒服地指出我的手指在OEM厂商了。

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)

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

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) {
        }
    }
}

The root cause most be:

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

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

EDIT: 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);
        }
    }

解决方案

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

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

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. Open your app, make sure a WebView is showing.
  2. Open Play Store, navigate to "My Apps," and bring up "Android System WebView." Uninstall updates. This shouldn't crash you, but you should see your app force-restart.
  3. Open your app back up and let it recover from the restart.
  4. Go back into the Play Store and update Android System WebView.
  5. Re-focus your app during the update process. Now, if you're on an affected device, it should crash. If not, your app will just be pushed to the background and quietly restarted.

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

  • 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.

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.

Edit: 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.

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

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