Tencent/tinker · error · IllegalStateException

AssetManager add SharedLibrary Fail

Error message

AssetManager add SharedLibrary Fail

What it means

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.

Source

Thrown at tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerResourcePatcher.java:250

            return;
        }

        newAssetManager = (AssetManager) newAssetManagerCtor.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

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Inspect context.getApplicationInfo().sharedLibraryFiles on the failing device and confirm every .apk entry exists and opens.
  2. Update Tinker — later versions tolerate individual shared-library add failures more gracefully.
  3. If the shared library entry is stale, force a full app reinstall/patch re-application to refresh the paths.
Defensive patterns

Strategy: try-catch

Validate before calling

ApplicationInfo ai = context.getApplicationInfo();
if (ai.sharedLibraryFiles != null) {
    for (String lib : ai.sharedLibraryFiles) {
        if (lib.endsWith(".apk") && !new File(lib).canRead()) {
            // stale shared library entry: resource patch may fail
        }
    }
}

Try / catch

try {
    TinkerResourcePatcher.monkeyPatchExistingResources(context, externalResourceFile);
} catch (IllegalStateException e) {
    // shared-library add failed: skip resource patch rather than crash app start
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14). Data as JSON: /api/errors/7835f59839c4899b. Report an issue: GitHub.