Return the same dex location for dex file whether backed by dex file or not.
Bug: 126901248
Test: oat_file_assistant_test
Change-Id: Idae49fb00bfad7007cc55e53a83e4a3e42f53e07
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 03cc658..c7cf43f 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -3757,15 +3757,18 @@
const size_t dex_cache_length = dex_cache_location.length();
CHECK_GT(dex_cache_length, 0u) << dex_file.GetLocation();
std::string dex_file_location = dex_file.GetLocation();
- CHECK_GE(dex_file_location.length(), dex_cache_length)
- << dex_cache_location << " " << dex_file.GetLocation();
- // Take suffix.
- const std::string dex_file_suffix = dex_file_location.substr(
- dex_file_location.length() - dex_cache_length,
- dex_cache_length);
- // Example dex_cache location is SettingsProvider.apk and
- // dex file location is /system/priv-app/SettingsProvider/SettingsProvider.apk
- CHECK_EQ(dex_cache_location, dex_file_suffix);
+ // The following paths checks don't work on preopt when using boot dex files, where the dex
+ // cache location is the one on device, and the dex_file's location is the one on host.
+ if (!(Runtime::Current()->IsAotCompiler() && class_loader == nullptr && !kIsTargetBuild)) {
+ CHECK_GE(dex_file_location.length(), dex_cache_length)
+ << dex_cache_location << " " << dex_file.GetLocation();
+ const std::string dex_file_suffix = dex_file_location.substr(
+ dex_file_location.length() - dex_cache_length,
+ dex_cache_length);
+ // Example dex_cache location is SettingsProvider.apk and
+ // dex file location is /system/priv-app/SettingsProvider/SettingsProvider.apk
+ CHECK_EQ(dex_cache_location, dex_file_suffix);
+ }
const OatFile* oat_file =
(dex_file.GetOatDexFile() != nullptr) ? dex_file.GetOatDexFile()->GetOatFile() : nullptr;
// Clean up pass to remove null dex caches; null dex caches can occur due to class unloading