问题遇到的现象和发生背景
使用微信Android热补丁Tinker框架在Android8.1.0系统不能加载layout资源,但values资源可以加载,使用相同的方法在Android5.1.0和Android7上可以
遇到的现象和发生背景,请写出第一个错误信息
使用微信Android热补丁Tinker框架在Android8.1.0系统不能加载layout资源,android.content.res.Resources$NotFoundException: Resource ID #0x7f23000d
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
if (externalResourceFile == null) {
return;
}
final ApplicationInfo appInfo = context.getApplicationInfo();
final Field[] packagesFields;
if (Build.VERSION.SDK_INT < 27) {
packagesFields = new Field[]{packagesFiled, resourcePackagesFiled};
} else {
packagesFields = new Field[]{packagesFiled};
}
for (Field field : packagesFields) {
final Object value = field.get(currentActivityThread);
for (Map.Entry<String, WeakReference<?>> entry
: ((Map<String, WeakReference<?>>) value).entrySet()) {
final Object loadedApk = entry.getValue().get();
if (loadedApk == null) {
continue;
}
// final String resDirPath = (String) resDir.get(loadedApk);
// if (appInfo.sourceDir.equals(resDirPath)) {
// resDir.set(loadedApk, externalResourceFile);
// }
}
}
if (isReInject) {
// ShareTinkerLog.i(TAG, "Re-injecting, skip rest logic.");
recordCurrentPatchedResModifiedTime(externalResourceFile);
return;
}
//先把宿主apk资源加入,防止宿主资源切换崩溃问题
if (((Integer) addAssetPathMethod.invoke(newAssetManager, context.getApplicationInfo().sourceDir)) == 0) {
throw new IllegalStateException("Could not create new AssetManager");
}
// newAssetManager = (AssetManager) newAssetManagerCtornewAssetManagerCtor.newInstance();
// Create a new AssetManager instance and point it to the resources installed under
if (((Integer) addAssetPathMethod.invoke(newAssetManager, externalResourceFile)) == 0) {
throw new IllegalStateException("Could not create new AssetManager");
}
recordCurrentPatchedResModifiedTime(externalResourceFile);
// Add SharedLibraries to AssetManager for resolve system resources not found issue
// This influence SharedLibrary Package ID
if (shouldAddSharedLibraryAssets(appInfo)) {
for (String sharedLibrary : appInfo.sharedLibraryFiles) {
if (!sharedLibrary.endsWith(".apk")) {
continue;
}
if (((Integer) addAssetPathAsSharedLibraryMethod.invoke(newAssetManager, sharedLibrary)) == 0) {
throw new IllegalStateException("AssetManager add SharedLibrary Fail");
}
// ShareTinkerLog.i(TAG, "addAssetPathAsSharedLibrary " + sharedLibrary);
}
}
// Kitkat needs this method call, Lollipop doesn't. However, it doesn't seem to cause any harm
// in L, so we do it unconditionally.
if (stringBlocksField != null && ensureStringBlocksMethod != null) {
stringBlocksField.set(newAssetManager, null);
ensureStringBlocksMethod.invoke(newAssetManager);
}
for (WeakReference<Resources> wr : references) {
final Resources resources = wr.get();
if (resources == null) {
continue;
}
// Set the AssetManager of the Resources instance to our brand new one
try {
//pre-N
assetsFiled.set(resources, newAssetManager);
} catch (Throwable ignore) {
// N
final Object resourceImpl = resourcesImplFiled.get(resources);
// for Huawei HwResourcesImpl
final Field implAssets = ShareReflectUtil.findField(resourceImpl, "mAssets");
implAssets.set(resourceImpl, newAssetManager);
}
clearPreloadTypedArrayIssue(resources);
resources.updateConfiguration(resources.getConfiguration(), resources.getDisplayMetrics());
}
// Handle issues caused by WebView on Android N.
// Issue: On Android N, if an activity contains a webview, when screen rotates
// our resource patch may lost effects.
// for 5.x/6.x, we found Couldn't expand RemoteView for StatusBarNotification Exception
if (Build.VERSION.SDK_INT >= 24) {
try {
if (publicSourceDirField != null) {
publicSourceDirField.set(context.getApplicationInfo(), externalResourceFile);
}
} catch (Throwable ignore) {
// Ignored.
}
}
if (!checkResUpdate(context)) {
// throw new TinkerRuntimeException(ShareConstants.CHECK_RES_INSTALL_FAIL);
}
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
在补丁包中测试后怀疑是layout资源没有加载
我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”
解决该问题后付费悬赏