Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bundle/src/ctrip/android/bundle/hack/SysHacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public static void allClasses() throws HackAssertionException {
LoadedApk = Hack.into("android.app.LoadedApk");
}
ActivityThread = Hack.into("android.app.ActivityThread");
Resources = Hack.into(Resources.class);
if(Build.VERSION.SDK_INT >= 24) {
Resources = Hack.into("android.content.res.ResourcesImpl");
} else {
Resources = Hack.into("android.content.res.Resources");
}
Application = Hack.into(Application.class);
AssetManager = Hack.into(AssetManager.class);
IPackageManager = Hack.into("android.content.pm.IPackageManager");
Expand Down
26 changes: 25 additions & 1 deletion bundle/src/ctrip/android/bundle/loader/BundlePathLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public static void installBundleDexs(ClassLoader loader, File dexDir, List<File>
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,InstantiationException,
InvocationTargetException, NoSuchMethodException, IOException {
if (!files.isEmpty()) {
if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT >= 24) {
V24.install(loader, files, dexDir, isHotFix);
} else if (Build.VERSION.SDK_INT >= 23) {
V23.install(loader, files, dexDir,isHotFix);
}else if (Build.VERSION.SDK_INT >= 19) {
V19.install(loader, files, dexDir,isHotFix);
Expand Down Expand Up @@ -154,6 +156,28 @@ private static void expandFieldArray(Object instance, String fieldName,
}
}

private static final class V24 {

private static void install(ClassLoader loader, List<File> additionalClassPathEntries,
File optimizedDirectory,boolean isHotFix)
throws IllegalArgumentException, IllegalAccessException,
NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException {

Field pathListField = findField(loader, "pathList");
Object dexPathList = pathListField.get(loader);
Field dexElementField = findField(dexPathList, "dexElements");
Object dexElements = dexElementField.get(dexPathList);
Class<?> elementType = dexElementField.getType().getComponentType();
Method loadDex = findMethod(dexPathList, "loadDexFile", File.class, File.class, ClassLoader.class, dexElementField.getType());
Object dex = loadDex.invoke(dexPathList, additionalClassPathEntries.get(0), optimizedDirectory, loader, dexElements);
Constructor<?> constructor = elementType.getConstructor(File.class, boolean.class, File.class, DexFile.class);
Object element = constructor.newInstance(new File(""), false, additionalClassPathEntries.get(0), dex);
Object[] newEles=new Object[1];
newEles[0]=element;
expandFieldArray(dexPathList, "dexElements",newEles,isHotFix);
}

}

private static final class V23 {

Expand Down