For some reason, my application likes to work just fine when ran on API 23 (Marshmallow) or higher. But when it tries to run on API 22 (Lollipop), it crashes instantly, and I just don't understand why.
I've tried commenting out anything except for the bare minimum even, yet it would still do this. I found that the application wouldn't even launch without commenting out all webviews.
This is the logcat I got from trying to start the app in Android Studio emulating a Pixel 2 on API 22. And for further reference, yes, I tried it without my custom WebView class, and it still throws the same error.
09-22 15:07:55.644 3443-3443/? I/art: Not late-enabling -Xcheck:jni (already on)
09-22 15:07:55.727 3443-3443/test.webview W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter
androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.
PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have
incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-22 15:07:55.749 3443-3443/test.webview I/art: Rejecting re-init on previously-failed class java.lang.Class<
androidx.core.view.ViewCompat$2>
09-22 15:07:55.750 3443-3443/test.webview I/art: Rejecting re-init on previously-failed class java.lang.Class<
androidx.core.view.ViewCompat$2>
09-22 15:07:55.808 3443-3443/test.webview I/WebViewFactory: Loading com.android.webview version 39 (5525941-x86_64
) (code 300008)
09-22 15:07:55.812 3443-3443/test.webview I/LibraryLoader: Time to load native libraries: 1 ms (timestamps 9226-
9227)
09-22 15:07:55.812 3443-3443/test.webview I/LibraryLoader: Expected native library version number "",actual native
library version number ""
09-22 15:07:55.817 3443-3443/test.webview V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper
(main, tid 1) {204b24c3}
09-22 15:07:55.817 3443-3443/test.webview I/LibraryLoader: Expected native library version number "",actual native
library version number ""
09-22 15:07:55.817 3443-3443/test.webview I/chromium: [INFO:library_loader_hooks.cc(104)] Chromium logging enabled
: level = 0, default verbosity = 0
09-22 15:07:55.819 3443-3443/test.webview I/BrowserStartupController: Initializing chromium process, singleProcess
=true
09-22 15:07:55.820 3443-3443/test.webview W/art: Attempt to remove local handle scope entry from IRT, ignoring
09-22 15:07:55.827 3443-3443/test.webview W/chromium: [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
09-22 15:07:55.828 3443-3443/test.webview I/chromium: [INFO:aw_browser_main_parts.cc(65)] Load from apk succesful
, fd=31 off=46184 len=3037
09-22 15:07:55.828 3443-3443/test.webview I/chromium: [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.
pak from, fd:32 off:229484 len:1089587
09-22 15:07:55.829 3443-3467/test.webview W/AudioManagerAndroid: Requires BLUETOOTH permission
09-22 15:07:55.854 3443-3443/test.webview D/EGL_emulation: eglCreateContext: 0x7fa99e8df2a0: maj 2 min 0 rcv 2
09-22 15:07:55.855 3443-3443/test.webview D/EGL_emulation: eglMakeCurrent: 0x7fa99e8df2a0: ver 2 0 (tinfo
0x7fa99e8d4a60)
09-22 15:07:55.877 3443-3443/test.webview W/chromium: [WARNING:data_reduction_proxy_settings.cc(331)] SPDY proxy
OFF at startup
09-22 15:07:55.882 3443-3443/test.webview W/ResourceType: No known package when getting value for resource number
0x02040003
09-22 15:07:55.882 3443-3443/test.webview D/AndroidRuntime: Shutting down VM
09-22 15:07:55.883 3443-3443/test.webview E/AndroidRuntime: FATAL EXCEPTION: main
Process: test.webview, PID: 3443
java.lang.RuntimeException: Unable to start activity ComponentInfo{test.webview/test.webview.MainActivity}:
android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.WebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.
WebView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at test.webview.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at test.webview.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
at android.content.res.Resources.getText(Resources.java:299)
at android.content.res.Resources.getString(Resources.java:385)
at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:
631)
at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:
123)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
at android.webkit.WebView.<init>(WebView.java:554)
at android.webkit.WebView.<init>(WebView.java:489)
at android.webkit.WebV
I was expecting it to launch (and maybe not look the best since webview support is different when going to older APIs), but instead it seems to crash because of an inflation exception? (unless I'm reading that wrong)
Edit: I just tried creating an entirely new application using just 1 WebView, simple too, and it also crashes. Here's the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
And here's the MainActivity.java
package test.webview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("https://google.com");
}
}
As you can see, nothing wrong with the code. So what could be wrong? (you can also test it for yourself on Lollipop)
Turns out to be some bug in the either the old version of Android System Webview that is included with AVD, or it's because of a bug in the AppCompat build version (1.1.0). Doing what this answer said, got my app working again. This works for me since I don't really use anything special in 1.1.0, so using 1.0.2 is just fine for androidx.appcompat:appcompat:1.0.2