由于某种原因,我的应用程序喜欢在API 23(棉花糖)或更高版本上运行时工作正常。但是当它尝试在API 22(Lollipop)上运行时,它立即崩溃,我只是不明白为什么。
我尝试注释掉除最低限度外的所有内容,但它仍然会这样做。我发现该应用程序甚至必须在不注释所有Web视图的情况下才能启动。
这是我尝试通过在Android Studio中启动应用程序来模拟API 22上的Pixel 2而得到的日志。为了进一步参考,是的,我在没有自定义WebView类的情况下进行了尝试,并且仍然抛出相同的错误。
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
我期望它能启动(也许看起来不是最好的,因为使用旧API时Webview支持有所不同),但是它似乎由于通货膨胀异常而崩溃了? (除非我读错了)
编辑:我只是尝试仅使用1个WebView创建一个全新的应用程序,也很简单,并且它也崩溃了。这是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>
这是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");
}
}
如您所见,代码没有错。那怎么可能出问题了? (您也可以在棒棒糖上自行测试)
答案 0 :(得分:0)
在您的MainActivity
xml中,您已经声明了NoSuggestionsWebView
类。
该错误说明,在您的MainActivity
XML中,第17行NoSuggestionsWebView
无法膨胀。
您必须检查NoSuggestionsWebView
类,并检查您是否正在做与OS相关的工作或类似的事情。
答案 1 :(得分:0)
原来是AVD随附的旧版Android系统Webview中的某些错误,或者是由于AppCompat构建版本(1.1.0)中的错误。按照answer所说的做,使我的应用程序再次工作。这对我有用,因为我并没有真正使用1.1.0中的任何特殊内容,因此对于androidx.appcompat:appcompat:1.0.2