Skip to content

Commit

Permalink
fix(dynamic.host-multi-loader-ext): MultiDynamicContainer的ClassLoader…
Browse files Browse the repository at this point in the history
…去掉双亲委派逻辑

由于多个plugin的加载顺序不固定,所以一般应该是都打包了core.runtime.container的。
如果双亲委派的话,肯定容易出现不同plugin的Activity壳子子类和父类在不同ClassLoader的情况。

子类和父类在不同的ClassLoader会触发HasSameSignatureWithDifferentClassLoaders的校验,
使得本来不调用就不会被加载的新版本API新增类型(如ContextParams)被加载,从而在低版本机型上找不到类。

fix Tencent#1118
  • Loading branch information
shifujun committed Dec 2, 2022
1 parent 09f6a48 commit 86fbe77
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,23 @@ public ContainerClassLoader(String containerKey, InstalledApk installedApk, Clas
this.containerKey = containerKey;
this.apkFilePath = installedApk.apkFilePath;
}

@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class<?> c = findLoadedClass(name);
if (c == null) {
// 对于当前apk中的类不进行双亲委派查找
// 因为这个ClassLoader中的类比较特殊,Activity等壳子接口的方法上存在当前环境可能不存在的类,
// 比如ContextParams这种API 31新引入的类。如果采用双亲委派,PluginContainerActivity等基类
// 可能跨ClassLoader加载,会触发HasSameSignatureWithDifferentClassLoaders的校验,
// 进而加载所有方法签名上的类型,从而可能在低版本机器上报找不到类的错误。
try {
c = findClass(name);
} catch (ClassNotFoundException ignored) {
c = super.loadClass(name, resolve);
}
}
return c;
}
}
}

0 comments on commit 86fbe77

Please sign in to comment.