Android 系统(36)---Android O、N版本修改dex2oat编译选项

 Android O、N版本修改dex2oat编译选项,减少占用ROM空间或者加快安装速度
内容 (2018-02-09)
 
 

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

  1. --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文件的大小;

 

--compiler-filter

Time

Total size(KB)

Odex(KB)

Vdex(KB)

assume-verified

3.228s

36657

653

36004

extract

2.499s

36657

653

36004

verify

7.616s

36904

653

36251

quicken

9.539s

38978

717

38261

space-profile

7.949s

38978

717

38261

space

27.425s

107608

71321

36287

speed-profile

7.810s

38978

717

38261

speed

52.815s

107608

71321

36287

everything-profile

7.415s

38978

717

38261

everything

53.364s

109544

73281

36263

 

表格统计数据是根据下面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,系统)