Android 安装apk时,是否可以将一个apk中的所有dex转换为oat?

Android 安装apk时,是否可以将一个apk中的所有dex转换为oat?,android,dex,android-runtime,dex2oat,Android,Dex,Android Runtime,Dex2oat,我在Android中发现了以下代码: bool DexFile::OpenFromZip(const ZipArchive& zip_archive, const std::string& location, std::string* error_msg, std::vector<const DexFile*>* dex_files) { ZipOpenErrorCode error_code; st

我在Android中发现了以下代码:

bool DexFile::OpenFromZip(const ZipArchive& zip_archive, const std::string& location,
                          std::string* error_msg, std::vector<const DexFile*>* dex_files) {
    ZipOpenErrorCode error_code;
    std::unique_ptr<const DexFile> dex_file(Open(zip_archive, kClassesDex, location, error_msg,
                                               &error_code));
    if (dex_file.get() == nullptr) {
      return false;
    } else {
      // Had at least classes.dex.
      dex_files->push_back(dex_file.release());

      // Now try some more.
      size_t i = 2;
      while (i &lt 100) {
      // We could try to avoid std::string allocations by working on a char array directly. As we
      // do not expect a lot of iterations, this seems too involved and brittle.
      std::string name = StringPrintf("classes%zu.dex", i);
      std::string fake_location = location + ":" + name;
      std::unique_ptr<const DexFile> next_dex_file(Open(zip_archive, name.c_str(), fake_location,
                                                        error_msg, &error_code));
      if (next_dex_file.get() == nullptr) {
        if (error_code != ZipOpenErrorCode::kEntryNotFound) {
          LOG(WARNING) << error_msg;
        }
        break;
      } else {
        dex_files->push_back(next_dex_file.release());
      }

      i++;
    }

    return true;
bool-DexFile::OpenFromZip(const-ZipArchive&zip\u存档,const-std::string&location,
std::字符串*错误消息,std::向量*索引文件){
ZipOpenErrorCode错误代码;
std::unique_ptr dex_文件(打开(zip_存档、KClassedEx、位置、错误消息、,
&错误代码);
if(dex_file.get()==nullptr){
返回false;
}否则{
//至少上过课。
dex_文件->向后推(dex_文件.release());
//现在再试试。
尺寸i=2;
而(i< 100){
//我们可以通过直接处理字符数组来避免std::string分配
//不要期待大量的迭代,这似乎太复杂和脆弱。
std::string name=StringPrintf(“类%zu.dex”,i);
std::string fake_location=location+“:”+name;
std::unique_ptr next_dex_文件(打开(zip_存档,name.c_str(),假位置,
错误消息和错误代码);
if(next_dex_file.get()==nullptr){
if(错误代码!=ZipoPennerRorCode::kEntryNotFound){
日志(警告)向后推(下一个索引文件.release());
}
i++;
}
返回true;
从主人那里

这是否意味着如果APK在根目录中有多个dex,那么在使用ART时,dex2oat将把所有dex都转换为OAT

如何在安装apk时将所有dex转换为oat

这是否意味着如果APK在根目录中有多个索引,那么dex2oat将全部 使用ART时,从DEX到OAT

是。oat文件结构“包含”许多dex文件:

这张照片是从保罗·萨巴纳尔那里拍的

现在,我如何在安装apk时将所有dex转换为oat

这是在安装过程中自动完成的