Revert "Revert "Prune uses library classes even without profile DO NOT MERGE""

No evidence that the fix was causing crashes.

Bug: 33718412
Bug: 30688277
Bug: 31427727

This reverts commit fc9bec20893d50f9c92c7c25845f2f425f4de052.

Test: test-art-host

Change-Id: Ib05e9a3ac6079ac246cb2ff00ea133aeddf5cbf3
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 61cf009..2d6c4da 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -789,6 +789,13 @@
   result = result || PruneAppImageClassInternal(klass->GetSuperClass(),
                                                 &my_early_exit,
                                                 visited);
+  // Remove the class if the dex file is not in the set of dex files. This happens for classes that
+  // are from uses library if there is no profile. b/30688277
+  mirror::DexCache* dex_cache = klass->GetDexCache();
+  if (dex_cache != nullptr) {
+    result = result ||
+        dex_file_oat_index_map_.find(dex_cache->GetDexFile()) == dex_file_oat_index_map_.end();
+  }
   // Erase the element we stored earlier since we are exiting the function.
   auto it = visited->find(klass);
   DCHECK(it != visited->end());