Let classloader provide correct LD_LIBRARY_PATH

Rely on BaseDexClassLoader to provide correct LD_LIBRARY_PATH

Bug: http://b/21647354
Bug: http://b/21667767
Bug: http://b/8076853
Change-Id: I8c690a2578d5de43be9da964fa5a4c0246aa6eec
diff --git a/runtime/native/java_lang_Runtime.cc b/runtime/native/java_lang_Runtime.cc
index bd043a8..abac815 100644
--- a/runtime/native/java_lang_Runtime.cc
+++ b/runtime/native/java_lang_Runtime.cc
@@ -52,52 +52,29 @@
   exit(status);
 }
 
-static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPathJstr, jstring javaDexPathJstr) {
+static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPathJstr) {
 #ifdef HAVE_ANDROID_OS
-  std::stringstream ss;
   if (javaLdLibraryPathJstr != nullptr) {
-    ScopedUtfChars javaLdLibraryPath(env, javaLdLibraryPathJstr);
-    if (javaLdLibraryPath.c_str() != nullptr) {
-      ss << javaLdLibraryPath.c_str();
+    ScopedUtfChars ldLibraryPath(env, javaLdLibraryPathJstr);
+    if (ldLibraryPath.c_str() != nullptr) {
+      android_update_LD_LIBRARY_PATH(ldLibraryPath.c_str());
     }
   }
 
-  if (javaDexPathJstr != nullptr) {
-    ScopedUtfChars javaDexPath(env, javaDexPathJstr);
-    if (javaDexPath.c_str() != nullptr) {
-      std::vector<std::string> dexPathVector;
-      Split(javaDexPath.c_str(), ':', &dexPathVector);
-
-      for (auto abi : art::Runtime::Current()->GetCpuAbilist()) {
-        for (auto zip_path : dexPathVector) {
-          // Native libraries live under lib/<abi>/ inside .apk file.
-          ss << ":" << zip_path << "!" << "lib/" << abi;
-        }
-      }
-    }
-  }
-
-  std::string ldLibraryPathStr = ss.str();
-  const char* ldLibraryPath = ldLibraryPathStr.c_str();
-  if (*ldLibraryPath == ':') {
-    ++ldLibraryPath;
-  }
-
-  android_update_LD_LIBRARY_PATH(ldLibraryPath);
 #else
   LOG(WARNING) << "android_update_LD_LIBRARY_PATH not found; .so dependencies will not work!";
-  UNUSED(javaLdLibraryPathJstr, javaDexPathJstr, env);
+  UNUSED(javaLdLibraryPathJstr, env);
 #endif
 }
 
 static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, jobject javaLoader,
-                                  jstring javaLdLibraryPathJstr, jstring javaDexPathJstr) {
+                                  jstring javaLdLibraryPathJstr) {
   ScopedUtfChars filename(env, javaFilename);
   if (filename.c_str() == nullptr) {
     return nullptr;
   }
 
-  SetLdLibraryPath(env, javaLdLibraryPathJstr, javaDexPathJstr);
+  SetLdLibraryPath(env, javaLdLibraryPathJstr);
 
   std::string error_msg;
   {
@@ -130,7 +107,7 @@
   NATIVE_METHOD(Runtime, gc, "()V"),
   NATIVE_METHOD(Runtime, maxMemory, "!()J"),
   NATIVE_METHOD(Runtime, nativeExit, "(I)V"),
-  NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
+  NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String;"),
   NATIVE_METHOD(Runtime, totalMemory, "!()J"),
 };
 
diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc
index e7857a0..0c7cce9 100644
--- a/runtime/well_known_classes.cc
+++ b/runtime/well_known_classes.cc
@@ -369,7 +369,7 @@
 
 void WellKnownClasses::LateInit(JNIEnv* env) {
   ScopedLocalRef<jclass> java_lang_Runtime(env, env->FindClass("java/lang/Runtime"));
-  java_lang_Runtime_nativeLoad = CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad", "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
+  java_lang_Runtime_nativeLoad = CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad", "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String;");
 }
 
 mirror::Class* WellKnownClasses::ToClass(jclass global_jclass) {