膨胀 WebView XML 时出错

Posted

技术标签:

【中文标题】膨胀 WebView XML 时出错【英文标题】:Error inflating WebView XML 【发布时间】:2015-10-21 12:56:40 【问题描述】:

我在三星 SM G920F (Galaxy S6) 版本 5.1.1 中发现了一份关于 Crashlytics 的崩溃报告(在所有其他设备上我没有检索到相同的错误)。

java.lang.RuntimeException: Unable to start activity ComponentInfocom.mypackage/com.mypackage.myactivity: 
android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView

这是我的webview的布局(样式为空样式):

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_webview_id"
    style="@style/MyEmptyStyle"
    android:layout_
    android:layout_
    android:background="@android:color/transparent" />

这就是我将它包含在活动布局中的方式:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_
    android:layout_>

    <include layout="@layout/my_webview_layout"
        android:visibility="gone"/>
</LinearLayout>

报告的错误是 XML 错误,因此我提供了所有代码(简化)。 这是一份报告,因此仅在此设备上发生过一次,有人可以解释一下原因吗?

编辑(完整的堆栈跟踪)

java.lang.RuntimeException: Unable to start activity ComponentInfocom.mypackage/com.mypackage.myactivity: android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
       at android.view.LayoutInflater.createView(LayoutInflater.java:640)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
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:614)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:174)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:109)
       at android.webkit.WebView.getFactory(WebView.java:2202)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2197)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2256)
       at android.view.View.<init>(View.java:3843)
       at android.view.View.<init>(View.java:3954)
       at android.view.ViewGroup.<init>(ViewGroup.java:513)
       at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
       at android.webkit.WebView.<init>(WebView.java:553)
       at android.webkit.WebView.<init>(WebView.java:498)
       at android.webkit.WebView.<init>(WebView.java:481)
       at android.webkit.WebView.<init>(WebView.java:468)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:614)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
       at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:167)
       at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:146)
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:109)
       at android.webkit.WebView.getFactory(WebView.java:2202)
       at android.webkit.WebView.ensureProviderCreated(WebView.java:2197)
       at android.webkit.WebView.setOverScrollMode(WebView.java:2256)
       at android.view.View.<init>(View.java:3843)
       at android.view.View.<init>(View.java:3954)
       at android.view.ViewGroup.<init>(ViewGroup.java:513)
       at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
       at android.webkit.WebView.<init>(WebView.java:553)
       at android.webkit.WebView.<init>(WebView.java:498)
       at android.webkit.WebView.<init>(WebView.java:481)
       at android.webkit.WebView.<init>(WebView.java:468)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:614)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
       at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
       at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
       at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
       at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
       at android.app.Activity.performCreateCommon(Activity.java:6492)
       at android.app.Activity.performCreate(Activity.java:6521)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
       at android.app.ActivityThread.access$1000(ActivityThread.java:198)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6837)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

【问题讨论】:

您可以发布MyEmptyStyle 并完成异常的堆栈跟踪吗? @Blackbelt 正如我所说MyEmptyStyle 是一个空样式,请参阅堆栈跟踪的编辑 NameNotFoundException: com.google.android.webview 他们没有安装它。它可能是一个自定义 rom,imo @Blackbelt idk,可能是对的,但我可以看到手机没有像我预期的那样扎根.. 你运行什么系统?您的 ROM 中似乎没有 google 软件包。 【参考方案1】:

当应用程序膨胀 WebView 时似乎发生了一些奇怪的事情,可能是什么。

对于NameNotFoundException: com.google.android.webview,我可以推断出这可能是 Google 软件包的问题(用户可能正在使用自定义 ROM 而没有安装它们。)

如果你有更多关于错误终端的信息,我会说你去吧,但你必须看到你拥有的用户/users_with_this_error 的比例。然后你可以看看它对你在这个问题上的工作是否有用。

来自断线的评论: 看看这个帖子,看起来有点像同一个问题:NameNotFoundException webview

【讨论】:

我知道如果我没有找到解决方案的比例太小了,我不需要“修复”这个问题,但我只是好奇 我已经编辑了部分解决方案以澄清更多疑问,我会继续编辑,直到我看不到更多内容为止。 我参考了断线的评论来改进您的答案。我不想让这个赏金无故过期,所以我会接受你的回答作为其他用户的“总结”【参考方案2】:

我在 crashlytics 上遇到了同样的错误。

在 Google 上进行了一些搜索后,似乎当用户没有在手机上安装 webview 时会发生这种情况。

这听起来很奇怪,因为 webview 是一个系统包,但是有一个错误,当用户使用应用程序时更新 webview 包时,它实际上是可能的。 它不适用于所有手机,因此可以在某些特定设备上复制(我猜主要是三星设备...),但不能在其他设备上复制。

我不记得确切的步骤复制它,但类似:

启动应用程序 前往 Play 商店并卸载 Web 视图更新 开始安装更新并切换回应用程序 在某些设备上,在更新结束时,应用程序会重新启动并且运行良好。在某些情况下,会出现错误,如果您尝试加载 web 视图,它会崩溃。

不知道如何处理它。 我想您可以查看软件包是否存在或注册以收到有关软件包更新的通知以重新加载应用程序。 就我而言,这确实是一个极端情况,发生了一两次,我认为不需要解决这个问题。如果它更频繁地发生,可能需要采取一些措施。

【讨论】:

对我来说同样的问题..如何解决这个问题 我个人没有提供任何修复。我认为您有两种方法:要么围绕 setContentView 进行尝试/捕获:如果由于找不到包异常而中断,则可以尝试向客户端显示错误或简单地重新加载应用程序(不确定是什么解决方案是最合适的)。或者,您可以在包更新事件中注册广播接收器,然后针对 webview 包 (***.com/questions/30727953/…) 重新启动您的应用程序【参考方案3】:

正如@simon-ninon 所说,这就是我在我的应用中实现的方式。

在 UI 中膨胀 Webview 的活动的 onCreate 中,您 可以有一个 try-catch 来避免在 崩溃分析。

  /**
     * This element touches the UI elements
     * of the application and set them up.
     */
   try 
        setContentView(R.layout.activity_main);
        // ... further setup
     catch (Exception ex) 
        transferToNoPackageFoundActivity(ex.getMessage());
    


    private void transferToNoPackageFoundActivity(String errorMessage) 
        Intent intent = new Intent(this, NoPackageFoundActivity.class);
        intent.putExtra(Intent.EXTRA_INTENT, errorMessage);
        startActivity(intent);
        finish();
    

在NoPackageFoundActivity中,可以带用户到Playstore下载webview包。

    /**
 * This field is used for presenting the user
 * with an error image for no connectivity.
 */
private lateinit var mErrorImage: ImageView

override fun onCreate(savedInstanceState: Bundle?) 
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_no_network)
    // get the intent for the error message, if any.
    val intent: Intent = intent
    if (intent.hasExtra(Intent.EXTRA_INTENT)) 
        println(intent.getStringExtra(Intent.EXTRA_INTENT))
    

    mErrorImage = findViewById(R.id.error_image)
    mErrorImage.contentDescription = resources.getString(R.string.no_network_image_desc)
    Glide.with(this)
            .load(R.drawable.ic_no_web_view_illustration)
            .into(mErrorImage)

    val enableButton = findViewById<Button>(R.id.error_handler_btn)
    enableButton.setOnClickListener  openGooglePlayStore() 
    enableButton.text = resources.getString(R.string.no_package_btn_text)

    val reloadText = findViewById<TextView>(R.id.no_network_reload)
    reloadText.setOnClickListener  reloadApplication() 

    val errorHeadingText = findViewById<TextView>(R.id.error_heading)
    val errorSubheadingText = findViewById<TextView>(R.id.error_subheading)
    errorHeadingText.text = resources.getString(R.string.no_package_heading_text)
    errorSubheadingText.text = resources.getString(R.string.no_package_subheading_text)


/**
 * This is a onClickListener Handler that
 * reloads the application when the user
 * clicks on it.
 * It starts the activity again from
 */
private fun reloadApplication() 
    val intent = Intent(this, SplashScreen::class.java)
    startActivity(intent)
    finish()


private fun openGooglePlayStore() 
    // you can also use BuildConfig.APPLICATION_ID
    val appId = "com.google.android.webview"
    val rateIntent = Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=$appId"))
    var marketFound = false
    // find all applications able to handle our rateIntent
    val otherApps = packageManager
            .queryIntentActivities(rateIntent, 0)
    for (otherApp in otherApps)  // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName
                == "com.android.vending") 
            val otherAppActivity = otherApp.activityInfo
            val componentName = ComponentName(
                    otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name
            )
            // make sure it does NOT open in the stack of your activity
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            // task reparenting if needed
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
            // if the Google Play was already open in a search result
            //  this make sure it still go to the app page you requested
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            // this make sure only the Google Play app is allowed to
            // intercept the intent
            rateIntent.component = componentName
            startActivity(rateIntent)
            marketFound = true
            break
        
    
    // if GP not present on device, open web browser
    if (!marketFound) 
        val webIntent = Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=$appId"))
        startActivity(webIntent)
    

【讨论】:

这是一个很好的回应,伙计!【参考方案4】:

在 Android 5.0 和 5.1 Lollipop (API 21/22) 上使用某些 AndroidX Jetpack 库的 1.1.0 版时会出现此崩溃问题:

implementation "androidx.appcompat:appcompat:1.1.0"

implementation "androidx.preference:preference:1.1.0"

当您的设备没有从 Google Play 商店安装 Google Chrome 浏览器或“Android System WebView”时,就会发生这种情况。因此,一些未安装 Google Play 服务的股票模拟器会遇到此问题。

如何解决

更新到更高的 AndroidX 版本,如 1.2.0-alpha03 将修复它,如下所述:

Error inflating class android.webkit.WebView Crash on Lollipop when opening PDF

implementation "androidx.appcompat:appcompat:1.2.0-alpha03"

或者在AppCompatActivity.applyOverrideConfiguration() 中使用自定义修复。见:android.view.InflateException Error inflating class android.webkit.WebView

另见:

WebView Crash on Android 5-5.1 (API 21-22) Resources$NotFoundException: String resource ID #0x2040002 https://issuetracker.google.com/issues/141132133 -- "webview 使用 appcompat1.1.0 崩溃"

【讨论】:

感谢这项工作,似乎在实现“androidx.appcompat:appcompat:1.1.0”中缺少一些库,但是在用更新版本实现“androidx.appcompat:appcompat:1.2”替换它之后.0-alpha03" 解决了我的问题。【参考方案5】:

我遇到了同样的问题,我通过在清单中更改其主题解决了这个问题

【讨论】:

你是如何解决这个问题的?你应用了什么主题?【参考方案6】:

当应用程序膨胀 WebView 时似乎发生了一些奇怪的事情,可能是什么。 对于 NameNotFoundException: com.google.android.webview Google 软件包的问题

 if(getPackageManager().hasSystemFeature("android.software.webview") == true && isPackageExisted("com.google.android.webview")) 
                if (Constant.isNetworkConnected(LoginActivity.this)) 

                     //Your Intent 
                 else 
                    Toast.makeText(getApplicationContext(), resources.getString(R.string.internet_error), Toast.LENGTH_SHORT).show();
                
            else
                
                    Constant.showDialog(LoginActivity.this,"Please install the webview");
                
        

//制作包检查方法

public boolean isPackageExisted(String targetPackage)
    List<ApplicationInfo> packages;
    PackageManager pm;

    pm = getPackageManager();
    packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) 
        if(packageInfo.packageName.equals(targetPackage))
            return true;
    
    return false;

【讨论】:

【参考方案7】:

我在 android 模拟器中测试我的应用程序时遇到了这个问题,这是因为在我的 android 模拟器中没有安装 google chrome 并通过安装 google chrome 进行修复

【讨论】:

以上是关于膨胀 WebView XML 时出错的主要内容,如果未能解决你的问题,请参考以下文章

【安卓开发】系统级APP使用webview时出错

自Lollipop以来,WebView的膨胀速度很慢

如果将 Webview 作为子项,则布局 onClick 事件不起作用

构建 android 应用程序时出错 (cordova-plugin-crosswalk-webview)

在 VStack 中包装 WebView 时出错:无法推断复杂的闭包返回类型;添加显式类型以消除歧义

在 html iframe 内的 Android webview 上播放音频时出错