From: Dmitriy Ivanov Date: Thu, 11 Jun 2015 22:42:34 +0000 (-0700) Subject: Revert "Let classloader provide correct LD_LIBRARY_PATH" X-Git-Tag: android-x86-7.1-r1~2347^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=95456e413497d3373fab3ef9bc78dea1c6b69dbc;p=android-x86%2Fart.git Revert "Let classloader provide correct LD_LIBRARY_PATH" This reverts commit 8117250a0bb57bf2aa6b1ab0c7d4d4a7dd402c08. --- diff --git a/runtime/native/java_lang_Runtime.cc b/runtime/native/java_lang_Runtime.cc index abac8153b..bd043a84c 100644 --- a/runtime/native/java_lang_Runtime.cc +++ b/runtime/native/java_lang_Runtime.cc @@ -52,29 +52,52 @@ NO_RETURN static void Runtime_nativeExit(JNIEnv*, jclass, jint status) { exit(status); } -static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPathJstr) { +static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPathJstr, jstring javaDexPathJstr) { #ifdef HAVE_ANDROID_OS + std::stringstream ss; if (javaLdLibraryPathJstr != nullptr) { - ScopedUtfChars ldLibraryPath(env, javaLdLibraryPathJstr); - if (ldLibraryPath.c_str() != nullptr) { - android_update_LD_LIBRARY_PATH(ldLibraryPath.c_str()); + ScopedUtfChars javaLdLibraryPath(env, javaLdLibraryPathJstr); + if (javaLdLibraryPath.c_str() != nullptr) { + ss << javaLdLibraryPath.c_str(); } } + if (javaDexPathJstr != nullptr) { + ScopedUtfChars javaDexPath(env, javaDexPathJstr); + if (javaDexPath.c_str() != nullptr) { + std::vector dexPathVector; + Split(javaDexPath.c_str(), ':', &dexPathVector); + + for (auto abi : art::Runtime::Current()->GetCpuAbilist()) { + for (auto zip_path : dexPathVector) { + // Native libraries live under lib// 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, env); + UNUSED(javaLdLibraryPathJstr, javaDexPathJstr, env); #endif } static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, jobject javaLoader, - jstring javaLdLibraryPathJstr) { + jstring javaLdLibraryPathJstr, jstring javaDexPathJstr) { ScopedUtfChars filename(env, javaFilename); if (filename.c_str() == nullptr) { return nullptr; } - SetLdLibraryPath(env, javaLdLibraryPathJstr); + SetLdLibraryPath(env, javaLdLibraryPathJstr, javaDexPathJstr); std::string error_msg; { @@ -107,7 +130,7 @@ static JNINativeMethod gMethods[] = { 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;"), + NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;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 0c7cce908..e7857a060 100644 --- a/runtime/well_known_classes.cc +++ b/runtime/well_known_classes.cc @@ -369,7 +369,7 @@ void WellKnownClasses::Init(JNIEnv* env) { void WellKnownClasses::LateInit(JNIEnv* env) { ScopedLocalRef 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;"); + 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;"); } mirror::Class* WellKnownClasses::ToClass(jclass global_jclass) {