Tencent/tinker · error · IllegalStateException
Could not create new AssetManager
Error message
Could not create new AssetManager
What it means
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.
Source
Thrown at tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerResourcePatcher.java:238
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;
}
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 harmView on GitHub (pinned to 1b7ea02c23)
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.
Defensive patterns
Strategy: validation
Validate before calling
File resApk = new File(patchDir, "resources.apk"); // actual name from info
if (!resApk.exists() || resApk.length() == 0
|| !SharePatchFileUtil.checkFileMd5(resApk, expectedMd5)) {
// reject before attempting AssetManager creation
cleanPatchAndReapply();
} Try / catch
try {
TinkerResourcePatcher.monkeyPatchExistingResources(context, externalResourceFile);
} catch (IllegalStateException e) { /* includes 'Could not create new AssetManager' */
// corrupt resource apk: wipe patch dir, request fresh patch
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Corrupted patch download/extraction; patch produced by a mismatched tinker gradle plugin; disk-full during patch extraction so resources apk is incomplete.
Related errors
- AssetManager add SharedLibrary Fail
- zipEntry is null when get from oldApk
- patch %s extract failed (%s).
- resource references is null
- Fail to hack resourceImpls field.
AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14).
Data as JSON: /api/errors/bef6c976f406b6c7.
Report an issue: GitHub.