libicu_jni needs to be initialized before libopenjdk{d}

java.lang.System, which implements System.loadLibrary, depends on ICU4CMetadata.
Thus, libicu_jni has to be loaded before libopenjdk, which initializes java.lang.System. Otherwise, the device fails to boot.
See b/143888405 for details.

Bug: 138994281
Bug: 143888405
Test: device boots
Change-Id: I3d6691be012601368820c3de717ee1268b6b7ca9
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 908a928..6d17204 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1862,6 +1862,16 @@
   // a regular JNI libraries with a regular JNI_OnLoad. Most JNI libraries can
   // just use System.loadLibrary, but libcore can't because it's the library
   // that implements System.loadLibrary!
+
+  // libicu_jni has to be initialized before libopenjdk{d} due to runtime dependency from
+  // libopenjdk{d} to Icu4cMetadata native methods in libicu_jni. See http://b/143888405
+  {
+    std::string error_msg;
+    if (!java_vm_->LoadNativeLibrary(
+          env, "libicu_jni.so", nullptr, WellKnownClasses::java_lang_Object, &error_msg)) {
+      LOG(FATAL) << "LoadNativeLibrary failed for \"libicu_jni.so\": " << error_msg;
+    }
+  }
   {
     std::string error_msg;
     if (!java_vm_->LoadNativeLibrary(
@@ -1879,13 +1889,6 @@
       LOG(FATAL) << "LoadNativeLibrary failed for \"" << kOpenJdkLibrary << "\": " << error_msg;
     }
   }
-  {
-    std::string error_msg;
-    if (!java_vm_->LoadNativeLibrary(
-          env, "libicu_jni.so", nullptr, WellKnownClasses::java_lang_Object, &error_msg)) {
-      LOG(FATAL) << "LoadNativeLibrary failed for \"libicu_jni.so\": " << error_msg;
-    }
-  }
 
   // Initialize well known classes that may invoke runtime native methods.
   WellKnownClasses::LateInit(env);