Home » Android » Android dex2oat build:ERROR: Dex2oat failed to compile a boot image-Exceptionshub

Android dex2oat build:ERROR: Dex2oat failed to compile a boot image-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

build Android 9.0

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

How to&Answers:

when apply the below patch can reslove the dexoat,but still break build 99% and always waiting .

From a177377c4f206c7c4c5463158cf83af65fae17a9 Mon Sep 17 00:00:00 2001
Date: Wed, 3 Jul 2019 14:28:40 +0800
Subject: [PATCH] Revert "Use FdFile::Copy() in dex2oat for better error
 checking."

This reverts commit b55cc6df451e7653baf6f49dce1f2a0c03ba4bc6.
---
 dex2oat/dex2oat.cc | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index fe927bbc1c..974eaec711 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2223,14 +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);
         }
         if (out->FlushCloseOrErase() != 0) {
           PLOG(ERROR) << "Failed to flush and close copied oat file: " << oat_unstripped_[i];
-- 
2.19.1

Answer:

now we use the below workaround method
export WITH_DEXPREOPT=falsee to disable dex2oat