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

在这里插入图片描述

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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值