{"record":{"id":"7835f59839c4899b","repo":"Tencent/tinker","slug":"assetmanager-add-sharedlibrary-fail","errorCode":null,"errorMessage":"AssetManager add SharedLibrary Fail","messagePattern":"AssetManager add SharedLibrary Fail","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerResourcePatcher.java","lineNumber":250,"sourceCode":"            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\n        // in L, so we do it unconditionally.\n        if (stringBlocksField != null && ensureStringBlocksMethod != null) {\n            stringBlocksField.set(newAssetManager, null);\n            ensureStringBlocksMethod.invoke(newAssetManager);\n        }\n\n        for (WeakReference<Resources> wr : references) {\n            final Resources resources = wr.get();\n            if (resources == null) {\n                continue;\n            }\n            // Set the AssetManager of the Resources instance to our brand new one","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerResourcePatcher.java#L232-L268","documentation":"After addAssetPath on the patched apk, Tinker adds each entry of ApplicationInfo.sharedLibraryFiles via addAssetPathAsSharedLibrary so that shared-library package IDs resolve. This error means one of those .apk entries returned 0 — the system could not load it as a shared library resource container.","triggerScenarios":"appInfo.sharedLibraryFiles containing an apk path that no longer exists or is invalid on the current device; a shared library apk that is not a valid resource container; OEM-injected entries pointing at inaccessible files.","commonSituations":"Apps using sharedUserId/shared libraries or Wear/Instant-app style splits; devices where the shared library apk was updated or removed between patch generation and load.","solutions":["Inspect context.getApplicationInfo().sharedLibraryFiles on the failing device and confirm every .apk entry exists and opens.","Update Tinker — later versions tolerate individual shared-library add failures more gracefully.","If the shared library entry is stale, force a full app reinstall/patch re-application to refresh the paths."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"ApplicationInfo ai = context.getApplicationInfo();\nif (ai.sharedLibraryFiles != null) {\n    for (String lib : ai.sharedLibraryFiles) {\n        if (lib.endsWith(\".apk\") && !new File(lib).canRead()) {\n            // stale shared library entry: resource patch may fail\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    TinkerResourcePatcher.monkeyPatchExistingResources(context, externalResourceFile);\n} catch (IllegalStateException e) {\n    // shared-library add failed: skip resource patch rather than crash app start\n}","preventionTips":["Update Tinker; newer versions are more tolerant of shared-library add failures.","Validate sharedLibraryFiles on QA devices that use shared-library resources.","Fall back to dex-only patches on ROMs with broken shared-library entries."],"tags":["android","assetmanager","shared-library","resources","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}