Android dex2oat 导致编译失败:ERROR: Dex2oat failed to compile a boot image

博客讲述了在Android 9.0编译时遇到Dex2oat无法编译启动映像的错误,提示启动类路径可能不一致。尝试百度、谷歌的方法未能解决,从错误日志找出失败原因,给出修改方式解决问题,该方法或适用于Android 8.0。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android 9.0 编译时遇到了以下错误:

ERROR: Dex2oat failed to compile a boot image. It is likely that the boot classpath is inconsistent. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS=–runtime-arg -verbose:verifier to see verification errors.

Baidu,google的方法全部都尝试了以下,仍然不能解决该问题.

从error log看出fail的原因是Failed to copy oat file to file:out/xx/xxx/....失败,这部分对应的源码是art/dex2oat/dex2oat.cc
 

@@ -2223,15 +2223,15 @@ class Dex2Oat FINAL {

         TimingLogger::ScopedTiming t("dex2oat OatFile copy", timings_);

         std::unique_ptr<File> in(OS::OpenFileForReading(oat_filenames_[i]));

         std::unique_ptr<File> out(OS::CreateEmptyFile(oat_unstripped_[i]));

        int64_t in_length = in->GetLength();

        if (in_length < 0) {

          PLOG(ERROR) << "Failed to get the length of oat file: " << in->GetPath();

          return false;

        }

        if (!out->Copy(in.get(), 0, in_length)) {

          PLOG(ERROR) << "Failed to copy oat file to file: " << out->GetPath();

          return false;

        }

 

按照如下方式修改,即可解决问题.该方法应该也适用于Android 8.0编译出现这个错误.

 

diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index fe927bb..4e0382a 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2223,15 +2223,15 @@ class Dex2Oat FINAL {
         TimingLogger::ScopedTiming t("dex2oat OatFile copy", timings_);
         std::unique_ptr<File> in(OS::OpenFileForReading(oat_filenames_[i]));
         std::unique_ptr<File> out(OS::CreateEmptyFile(oat_unstripped_[i]));
-        int64_t in_length = in->GetLength();
-        if (in_length < 0) {
-          PLOG(ERROR) << "Failed to get the length of oat file: " << in->GetPath();
-          return false;
-        }
-        if (!out->Copy(in.get(), 0, in_length)) {
-          PLOG(ERROR) << "Failed to copy oat file to file: " << out->GetPath();
-          return false;
-        }
+        size_t buffer_size = 8192;
+       std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
+       while (true) {
+               int bytes_read = TEMP_FAILURE_RETRY(read(in->Fd(), buffer.get(), buffer_size));
+               if (bytes_read <= 0)
+                       break;
+               bool write_ok = out->WriteFully(buffer.get(), bytes_read);
+               CHECK(write_ok);
+       }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值