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

使用微信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条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

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

      悬赏问题

      • ¥15 matlab数据信号处理问题
      • ¥15 为什么Js中函数还可以有实例对象?
      • ¥15 一块长方形的大布料截取若干个小的长方形布料,小长方形布料不能旋转,怎么使组成的不规则图形的长度最小?
      • ¥15 iPhone13视频通话屏幕闪黑
      • ¥15 linux平台中qt5对触屏操作偶尔不响应
      • ¥15 不使用zk实现双机clickhouse、kafka数据同步
      • ¥15 使用Labwindows/CVI程控万用表时自动切换量程
      • ¥15 Matlab修改xml参数后允许不了exe文件
      • ¥15 用flask框架接收前端上传的文本文件后怎么读取该文件
      • ¥15 有没有嵌入式ubuntu的朋友