Merge "Revert "Revert "Fixed installation time regression when compile.""" am: 16d59b2b0f
am: 29a15f2718

Change-Id: I783b7b318fa2261d051c903274be3191e850f1de
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 0d0769f..cd1f466 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -2293,9 +2293,18 @@
         ObjectLock<mirror::Class> lock(soa.Self(), h_klass);
         // Attempt to initialize allowing initialization of parent classes but still not static
         // fields.
-        bool is_superclass_initialized = InitializeDependencies(klass, class_loader, soa.Self());
-        if (is_superclass_initialized) {
+        bool is_superclass_initialized = true;
+        if (!manager_->GetCompiler()->GetCompilerOptions().IsAppImage()) {
+          // If not an app image case, the compiler won't initialize too much things and do a fast
+          // fail, don't check dependencies.
           manager_->GetClassLinker()->EnsureInitialized(soa.Self(), klass, false, true);
+        } else {
+          // For app images, do the initialization recursively and resolve types encountered to make
+          // sure the compiler runs without error.
+          is_superclass_initialized = InitializeDependencies(klass, class_loader, soa.Self());
+          if (is_superclass_initialized) {
+            manager_->GetClassLinker()->EnsureInitialized(soa.Self(), klass, false, true);
+          }
         }
         old_status = klass->GetStatus();
         // If superclass cannot be initialized, no need to proceed.