m0_71604222 2022-12-09 16:30 采纳率: 0%
浏览 38
已结题

使用微信Android热补丁Tinker框架在Android8.1.0系统不能加载layout资源,但values资源可以加载,使用相同的方法在Android5.1.0和Android7上可以

问题遇到的现象和发生背景

使用微信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资源没有加载

我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”

解决该问题后付费悬赏

  • 写回答

5条回答 默认 最新

  • yy64ll826 2022-12-09 16:59
    关注

    微信Android热补丁方案Tinker
    如有帮助,望采纳
    https://blog.csdn.net/Jay_Xio/article/details/124475390

    评论

报告相同问题?

问题事件

  • 系统已结题 12月17日
  • 创建了问题 12月9日

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题