使用微信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
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 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);
}
在补丁包中测试后怀疑是layout资源没有加载
解决该问题后付费悬赏
微信Android热补丁方案Tinker
如有帮助,望采纳
https://blog.csdn.net/Jay_Xio/article/details/124475390
http://www.ekangw.net/a/diannaojiqiao/2022/0831/181420.html
可以参考一下:
https://zhuanlan.zhihu.com/p/529820033?utm_id=0
热修复会存在兼容性问题,我们上架谷歌play是不允许热修复热更新的,我觉得题主还是不要用
我这边试了一下8.1的测试机,layout patch加载可以的。感觉应该是Tinker 对于您这个机型的系统的支持问题,因为Tinker 官方是支持8.x系统layout资源的patch机制的,我看了一下这块的源码,里面针对于华为、荣耀、小米特别的几个机型,都做了api if判断调用,基本都是通过反射调用的,所以猜测您的问题,应该是机型适配问题,您再找一个8.1的手机可以试试。