我使用DexClassloader从/ data / data / packagename /加载dex文件,就像:
private static synchronized Boolean injectAboveEqualApiLevel14(
String dexPath, String defaultDexOptPath, String nativeLibPath, String dummyClassName) {
BaseDexClassLoader pathClassLoader = (BaseDexClassLoader) DexInjector.class.getClassLoader();
DexClassLoader dexClassLoader = new DexClassLoader(dexPath, defaultDexOptPath, nativeLibPath, pathClassLoader);
try {
dexClassLoader.loadClass(dummyClassName);
Object dexElements = combineArray(
getDexElements(getPathList(pathClassLoader)),
getDexElements(getPathList(dexClassLoader)));
Object pathList = getPathList(pathClassLoader);
setField(pathList, pathList.getClass(), "dexElements", dexElements);
} catch (Throwable e) {
LogTool.i(TAG, "Throwable: " + e.toString() + "\n" + e.getMessage() + "\n");
e.printStackTrace();
return false;
}
return true;
}
它在大多数机器和系统上运行完美....... 但今天,用户反馈说dex文件无法加载,,,这里的重要性错误日志:
12-03 15:19:12.725: E/dalvikvm(32068): waitpid failed: wanted 32099, got -1: No child processes
12-03 15:19:12.725: E/dalvikvm(32068): Unable to extract+optimize DEX from '/data/data/com.test.plugin/dex/classes1.dex', err: No child processes
手机信息:HTC 9060,Android 4.2.2,HTC Sense 5.0
这是一个奇怪的错误。这是完整的日志:
12-03 15:19:12.725: E/dalvikvm(32068): waitpid failed: wanted 32099, got -1: No child processes
12-03 15:19:12.725: E/dalvikvm(32068): Unable to extract+optimize DEX from '/data/data/com.test.plugin/dex/classes1.dex', err: No child processes
12-03 15:19:12.725: E/System(32068): Unable to load dex file: /data/data/com.test.plugin/dex/classes1.dex
12-03 15:19:12.725: E/System(32068): java.io.IOException: unable to open DEX file
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexFile.openDexFile(Native Method)
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexFile.<init>(DexFile.java:109)
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexFile.loadDex(DexFile.java:149)
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexPathList.loadDexFile(DexPathList.java:251)
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexPathList.makeDexElements(DexPathList.java:210)
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexPathList.<init>(DexPathList.java:96)
12-03 15:19:12.725: E/System(32068): at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:56)
12-03 15:19:12.725: E/System(32068): at dalvik.system.DexClassLoader.<init>(DexClassLoader.java:57)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.a.a.d(ProGuard:153)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.a.a.a(ProGuard:46)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.b.a(ProGuard:41)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.c.a(ProGuard:104)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.c.a(ProGuard:79)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.c.a(ProGuard:69)
12-03 15:19:12.725: E/System(32068): at com.test.plugin.main.e.run(ProGuard:74)