欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ClassLoader的使用方式

程序员文章站 2022-03-10 22:43:50
public ClassLoader getClassLoader() {synchronized (this) {if (mClassLoader != null) {return mClassLoader;}// …// 创建加载器,创建默认的加载器// zip为Apk的路径,libraryPath也就是JNI的路径mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, libraryPath, mBaseCl...

public ClassLoader getClassLoader() {
synchronized (this) {
if (mClassLoader != null) {
return mClassLoader;
}
// …
// 创建加载器,创建默认的加载器
// zip为Apk的路径,libraryPath也就是JNI的路径
mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, libraryPath, mBaseClassLoader);
initializeJavaContextClassLoader();
StrictMode.setThreadPolicy(oldPolicy);
} else {
if (mBaseClassLoader == null) {
mClassLoader = ClassLoader.getSystemClassLoader();
} else {
mClassLoader = mBaseClassLoader;
}
}
return mClassLoader;
}
}
private void replaceClassLoader(DexClassLoader loader) {
try {
Class clazz_Ath = Class.forName(“android.app.ActivityThread”);
Class clazz_LApk = Class.forName(“android.app.LoadedApk”);
Object currentActivityThread = clazz_Ath.getMethod(“currentActivityThread”).invoke(null);
Field field1 = clazz_Ath.getDeclaredField(“mPackages”);
field1.setAccessible(true);
Map mPackages = (Map

本文地址:https://blog.csdn.net/qq_42894864/article/details/107880810