函数为
DexFile_openDexFileNative
ClassLinker::OpenDexFilesFromOat
1、 FindOpenedOatDexFile 查找缓存中是否存在,checksum为空或者相同
2、 CreateOatFileForDexLocation
一、生成oat文件 执行execv 调用 dex2oat 生成Oat 会启动进程生成较慢
std::string dex2oat(Runtime::Current()->GetCompilerExecutable()); 文件路径待研究
execv执行成功就返回成功,不管是不是成功
二、OatFile::Open打开,如果失败返回null OatFile* OatFile::Open
调用 ElfFile::Open 判断非ELF文件返回NULL
3、CreateOatFileForDexLocation 生成失败 调用 DexFile::Open 不生成优化
// Failed, bail.
if (open_oat_file.get() == nullptr) {
std::string error_msg;
// dex2oat was disabled or crashed. Add the dex file in the list of dex_files to make progress.
DexFile::Open(dex_location, dex_location, &error_msg, dex_files);
error_msgs->push_back(error_msg);
return false;
}
经过以上分析 内存打开Dex文件的时候 hook execv 然后失败,防止转换oat成功可以提高首次启动速度,且能
正常运行,但是每次的速度是变慢的,DEX加固的时候有的手机会出现卡死的情况(有buggly时才会出现),暂时
不知道原因,待以后研究明白在说明,如果有人知道原因也麻烦告知。