问题
After upgrading to "androidx.appcompat:appcompat:1.0.2" and "com.google.android.material:material:1.1.0-beta01" the WebView crashes on devices with Android 5.0 and throws this exeption android.view.InflateException
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.WebView
How can I fix it?
回答1:
What about your targetSdkVersion and your buildTools version? Once I had a very similar issue. I started seeing this exception when I raised the targetSdkVersion to 25 and the build tools to 25.0.2.
Also try to update your app theme to inherit from Theme.MaterialComponents (or a descendant). Change your AppTheme parent to Theme.MaterialComponents.
Example
Before:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
After:
<!-- Material application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
回答2:
As explained here, this issue is due to the this revision. It affects Lollipop devices with webview version<50. Use the following code as a solution.
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
if (Build.VERSION.SDK_INT in 21..25 && (resources.configuration.uiMode == AppConstants.appContext.resources.configuration.uiMode)) {
return
}
super.applyOverrideConfiguration(overrideConfiguration)
}
来源:https://stackoverflow.com/questions/58472000/webview-throws-inflateexception-on-android-5-0