Android O、N版本修改dex2oat编译选项,减少占用ROM空间或者加快安装速度

Android O版本、AndroidN版本

1.ROM过大可以通过调整–compiler-filter,减少apk生成odex文件所占据空间的大小,通常来说odex+vdex文件越大,说明dex2oat优化的类越多越彻底,性能也相对较好;

2.Apk安装时间过长可以通过调整–compiler-filter,加快安装;

解决方案:

修改dex2oat的–compiler-filter选项;

oat_location_为要修改apk的关键字,通常使用包名,比如微信:com.tencent.mm;

/art/dex2oat/dex2oat.cc

void ParseArgs(int argc, char** argv) {

original_argc = argc;

original_argv = argv;

InitLogging(argv, Runtime::Abort);

// Skip over argv[0].

argv++;

argc--;

if (argc == 0) {

  Usage("No arguments specified");

}

……

  } else if (option.starts_with("--dirty-image-objects=")) {

    dirty_image_objects_filename_ = option.substr(strlen("--dirty-image-objects=")).data();

  }  else if (!compiler_options_->ParseCompilerOption(option, Usage)) {

    Usage("Unknown argument %s", option.data());

  }

}



      /** MTK begin */

        if(oat_location_ != "" && (oat_location_.find("mtk14456") != std::string::npos || oat_location_.find("com.tencent.mm")!= std::string::npos)){

                    LOG(INFO) << "MTK oat_location_=" << oat_location_ << ",SetCompilerFilter=CompilerOptions::kQuicken";

                    compiler_options_->SetCompilerFilter(CompilerFilter::kQuicken);

        }

        /** MTK end */

       

ProcessOptions(parser_options.get());

// Insert some compiler things.

InsertCompileOptions(argc, argv);

}

下面以Android O版本,微信6.6.2为例:

步骤:

1.下载weixin.apk,重命名为weixin.zip;解压缩,把所有的dex文件push到sdcard

2.adb shell,然后执行下面的命令:

./system/bin/dex2oat --oat-file=/sdcard/mtk14456tools_everything.odex --dex-file=/sdcard/classes.dex --dex-file=/sdcard/classes2.dex --dex-file=/sdcard/classes3.dex --dex-file=/sdcard/classes4.dex --dex-file=/sdcard/classes5.dex --compiler-filter=everything

–compiler-filter参数如下:
–compiler-filter=(assume-verified|extract|verify|quicken|space-profile|space|speed-profile|speed|everything-profile|everything)

通过上面可以得出下面数据:

Time为安装apk时dex2oat的时间;

Odex表示生成odex文件的大小;

Vdex表示生成vdex文件的大小;

Android O、N版本修改dex2oat编译选项,减少占用ROM空间或者加快安装速度_第1张图片

表格统计数据是根据下面log和生成在sdcard的odex和vdex得出:

01-01 00:33:58.596 4332-4332/? I/dex2oat: StrippedCommandLine:./system/bin/dex2oat --oat-file=/sdcard/mtk14456tools_everything.odex --dex-file=/sdcard/classes.dex --dex-file=/sdcard/classes2.dex --dex-file=/sdcard/classes3.dex --dex-file=/sdcard/classes4.dex --dex-file=/sdcard/classes5.dex --compiler-filter=everything

01-01 00:34:51.958 4332-4332/? I/dex2oat: dex2oat took 53.364s (341.743s cpu) (threads: 8) arena alloc=27MB (28629200B) java alloc=24MB (25341840B) native alloc=128MB (135004032B) free=29MB (31195264B)

你可能感兴趣的:(Android)