已经2个星期还是无法解决这个问题,每天被PM追杀,Help me ~~~ Orz...
目前 App 满足下列3个条件将导致 WebView 发生 NotFoundException:
1. Android 7以上
2. chrome 升级到67版本以上
3. app 开启插件前有先使用过 WebView 元件
加载插件资源的方式:
protected void loadResources() throws InstantiationException, IllegalAccessException,
IllegalArgumentException,InvocationTargetException, NoSuchMethodException,
NoSuchFieldException {
mAssetManager = AssetManager.class.newInstance();
AssetManager.class.getMethod("addAssetPath", String.class).invoke(mAssetManager, dexPath);
//AssetManager.class.getMethod("addAssetPath", String.class).invoke(mAssetManager,
getSourceDir());
if (mResources == null) {
mResources = new Resources(mAssetManager, getResources().getDisplayMetrics(),
getResources().getConfiguration());
}
mTheme = mResources.newTheme();
mTheme.applyStyle(android.R.style.Theme_Light_NoTitleBar_Fullscreen, true);
}
参考:
https://www.jianshu.com/p/89e2a4165fb6
尝试:
1.尝试将 WebView 的资源加载进新的 AssetManager,但依旧是 NotFoundException
private String getSourceDir() {
String webviewImplPackageName = null;
PackageInfo packageInfo = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webviewImplPackageName = Settings.Global.getString(getApplication().getContentResolver(),
"webview_provider");
}
try {
packageInfo = getApplication().getPackageManager().getPackageInfo(webviewImplPackageName,
PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return packageInfo.applicationInfo.sourceDir;
}
2.尝试将 sharedLibraryFiles 清空,但依旧是 NotFoundException
private void delet() {
getApplicationInfo().sharedLibraryFiles = new String[0];
}
错误Log:
W/ResourceType: No known package when getting value for resource number 0x020b001b
W/System.err: android.content.res.Resources$NotFoundException: Resource ID #0x20b001b
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:209)
at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:91)
at android.content.res.Resources.getInteger(Resources.java:1096)
at org.chromium.ui.base.DeviceFormFactor.b(SourceFile:5)
at org.chromium.ui.base.DeviceFormFactor.isTablet(SourceFile:3)
at org.chromium.android_webview.AwSettings.nativeUpdateEverythingLocked(Native Method)
at org.chromium.android_webview.AwSettings.ac(SourceFile:71)
at org.chromium.android_webview.AwSettings.a(SourceFile:69)
at org.chromium.android_webview.AwContents.e(SourceFile:212)
at org.chromium.android_webview.AwContents.d(SourceFile:153)
at org.chromium.android_webview.AwContents.(SourceFile:81)
at uY.run(SourceFile:15)
at ahv.a(SourceFile:13)
at ahw.run(SourceFile:2)
at org.chromium.base.ThreadUtils.b(SourceFile:31)
at ahv.a(SourceFile:7)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.b(SourceFile:6)
at com.android.webview.chromium.WebViewChromium.init(SourceFile:111)
at android.webkit.WebView.(WebView.java:651)
at android.webkit.WebView.(WebView.java:581)
at android.webkit.WebView.(WebView.java:564)
at android.webkit.WebView.(WebView.java:551)
at android.webkit.WebView.(WebView.java:541)
at candan.sectionapk.MainActivity$1.onClick(MainActivity.java:50)
at android.view.View.performClick(View.java:6266)
at android.view.View$PerformClick.run(View.java:24730)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
A/chromium: [FATAL:jni_android.cc(258)] Please include Java exception stack in crash report
W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
Chrome build fingerprint:
68.0.3440.91
344009152