{"record":{"id":"bef6c976f406b6c7","repo":"Tencent/tinker","slug":"could-not-create-new-assetmanager","errorCode":null,"errorMessage":"Could not create new AssetManager","messagePattern":"Could not create new AssetManager","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerResourcePatcher.java","lineNumber":238,"sourceCode":"                    continue;\n                }\n                final String resDirPath = (String) resDir.get(loadedApk);\n                if (appInfo.sourceDir.equals(resDirPath)) {\n                    resDir.set(loadedApk, externalResourceFile);\n                }\n            }\n        }\n\n        if (isReInject) {\n            ShareTinkerLog.i(TAG, \"Re-injecting, skip rest logic.\");\n            recordCurrentPatchedResModifiedTime(externalResourceFile);\n            return;\n        }\n\n        newAssetManager = (AssetManager) newAssetManagerCtor.newInstance();\n        // Create a new AssetManager instance and point it to the resources installed under\n        if (((Integer) addAssetPathMethod.invoke(newAssetManager, externalResourceFile)) == 0) {\n            throw new IllegalStateException(\"Could not create new AssetManager\");\n        }\n        recordCurrentPatchedResModifiedTime(externalResourceFile);\n\n        // Add SharedLibraries to AssetManager for resolve system resources not found issue\n        // This influence SharedLibrary Package ID\n        if (shouldAddSharedLibraryAssets(appInfo)) {\n            for (String sharedLibrary : appInfo.sharedLibraryFiles) {\n                if (!sharedLibrary.endsWith(\".apk\")) {\n                    continue;\n                }\n                if (((Integer) addAssetPathAsSharedLibraryMethod.invoke(newAssetManager, sharedLibrary)) == 0) {\n                    throw new IllegalStateException(\"AssetManager add SharedLibrary Fail\");\n                }\n                ShareTinkerLog.i(TAG, \"addAssetPathAsSharedLibrary \" + sharedLibrary);\n            }\n        }\n\n        // Kitkat needs this method call, Lollipop doesn't. However, it doesn't seem to cause any harm","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerResourcePatcher.java#L220-L256","documentation":"Tinker creates a new AssetManager via reflection and calls addAssetPath(externalResourceFile) pointing at the patched resources apk. The method returns 0 when the path cannot be loaded as a resource table; Tinker treats that as fatal because the new AssetManager would silently contain no patched resources.","triggerScenarios":"externalResourceFile (the extracted resources-*.apk under the patch directory) missing, truncated, CRC-corrupted, or not a valid APK/ARSK container; wrong path passed due to patch layout mismatch between patch builder and loader versions.","commonSituations":"Corrupted patch download/extraction; patch produced by a mismatched tinker gradle plugin; disk-full during patch extraction so resources apk is incomplete.","solutions":["Verify the extracted resources apk exists, has non-zero size, and can be opened with aapt on a desktop.","Clean the patch directory and re-download/re-apply the patch (Tinker's md5/checksum flow should also be enabled to reject corrupt patches early).","Ensure the Tinker gradle plugin version matches the SDK version so patch layout and paths agree."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"File resApk = new File(patchDir, \"resources.apk\"); // actual name from info\nif (!resApk.exists() || resApk.length() == 0\n        || !SharePatchFileUtil.checkFileMd5(resApk, expectedMd5)) {\n    // reject before attempting AssetManager creation\n    cleanPatchAndReapply();\n}","typeGuard":null,"tryCatchPattern":"try {\n    TinkerResourcePatcher.monkeyPatchExistingResources(context, externalResourceFile);\n} catch (IllegalStateException e) { /* includes 'Could not create new AssetManager' */\n    // corrupt resource apk: wipe patch dir, request fresh patch\n}","preventionTips":["Enable md5 verification of extracted patch files before load.","Write patch files atomically (temp + rename) so partial extractions never reach the loader.","Watch for disk-space errors during patch download/extraction."],"tags":["android","assetmanager","resources","patch","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}