Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-10-12:PathClassLoader和DexClassLoader有何区别? #163

Open
Moosphan opened this issue Oct 12, 2019 · 3 comments
Open

2019-10-12:PathClassLoader和DexClassLoader有何区别? #163

Moosphan opened this issue Oct 12, 2019 · 3 comments

Comments

@Moosphan
Copy link
Owner

No description provided.

@canyie
Copy link

canyie commented Oct 12, 2019

PathClassLoader和DexClassLoader都是Android提供给我们的ClassLoader,都能加载dex
网上很多文章都说PathClassLoader只能加载已经被系统安装过的apk,DexClassLoader无此限制,然而我自己测试是都可以
根据art源码来看,两者都继承自BaseDexClassLoader,最终都会创建一个DexFile,不同点是一个关键的参数:optimizedDirectory,PathClassLoader为null,DexClassLoader则使用传递进来的
然后会根据optimizedDirectory判断对应的oat文件是否已经生成(null则使用/data/dalvik-cache/),如果有且该oat对应的dex正确则直接加载,否则触发dex2oat(就是这家伙耗了我们宝贵的时间!!),成功则用生成的oat,失败则走解释执行
ps:貌似Q版做了优化,不会再卡死在dex2oat里了
根据加载外部dex的实验,DexClassLoader会触发dex2oat,而PathClassLoader不会

@icytz
Copy link

icytz commented Nov 27, 2019

8.0前DexClassLoader多了一个optimizedDirectory,用来存dex2oat的目录,8.0后被废弃,两个完全一样

@mlinqirong
Copy link

PathClassLoader 加载系统中已安装的APK DEX JAR
DexClassLoader 加载APK DEX JAR 可以从SD卡中加载未安装的apk 并指定存放DEX 路径

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants