-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomizedDexClassLoader.java
40 lines (32 loc) · 1.24 KB
/
CustomizedDexClassLoader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package xakep.dexloader;
import java.io.File;
import java.util.concurrent.ExecutionException;
import android.content.Context;
import dalvik.system.DexClassLoader;
public class CustomizedDexClassLoader {
private static Context context;
private static DexClassLoader loader;
public static void setContext(Context context) {
CustomizedDexClassLoader.context = context;
}
public static DexClassLoader load(final String dexFileName, final String ccUrl) throws RuntimeException {
if(null == context) {
throw new RuntimeException("No context provided");
}
if(null == loader) {
final File dexInternalStoragePath = new File(context.getDir("dex", Context.MODE_PRIVATE), dexFileName);
if (!dexInternalStoragePath.exists()) {
try {
(new DexPreparationTask(context, ccUrl)).execute(dexInternalStoragePath).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
final File optimizedDexOutputPath = context.getDir("outdex", Context.MODE_PRIVATE);
loader = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, context.getClassLoader().getParent());
}
return loader;
}
}