From 4f00791aa2e6860188b4fdc4f64162b9d3d50587 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Thu, 7 Nov 2019 14:41:52 +0800 Subject: [PATCH] Rename libv8.so to libv8android.so Summary: On some Android device, there is libv8.so in system ROM. E.g. /system/lib/libv8.so or /vendor/lib/libv8.so On old Android, dlopen() with RTLD_GLOBAL is not handled well and it's by default RTLD_LOCAL. Even we call System.loadLibrary("v8") before, during the time RNV8 call System.loadLibrary("v8executor") and search libv8.so in DT_NEEDED. It seems bionic linker will use system libv8.so instead of ours. Since our libv8.so is customized with libplatform.so, this leads to unresolved symbol as https://github.com/Kudo/react-native-v8/issues/29. That's why I am proposing to rename libv8.so as libv8android.so and to prevent name conflict from system libv8.so. Reference for RTLD_GLOBAL: https://github.com/android/ndk/issues/201 (cherry picked from commit 5a78dd52b0678c18e62972ae5f6cb0f2025e28b4) --- README.md | 6 +++--- package.json | 5 ++++- src/androidexecutor/reactexecutor/Android.mk | 2 +- src/androidexecutor/reactexecutor/V8Executor.java | 2 -- src/patches/build_with_v8.patch | 2 +- src/sowrapper/Android.mk | 4 ++-- src/v8runtime/Android.mk | 2 +- yarn.lock | 8 ++++---- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 36795ee..1d4f02a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ yarn add 'react-native-v8@>=0.60.0-patch.0 <0.60.1' dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:+" // From node_modules -+ // Add v8-android - prebuilt libv8.so into APK ++ // Add v8-android - prebuilt libv8android.so into APK + implementation 'org.chromium:v8-android:+' // JSC from node_modules @@ -60,7 +60,7 @@ yarn add 'react-native-v8@>=0.60.0-patch.0 <0.60.1' + url("$rootDir/../node_modules/react-native-v8/dist") + } + maven { -+ // prebuilt libv8.so ++ // prebuilt libv8android.so + url("$rootDir/../node_modules/v8-android/dist") } maven { @@ -109,7 +109,7 @@ $ yarn add v8-android-nointl @@ -29,7 +29,7 @@ allprojects { } maven { - // prebuilt libv8.so + // prebuilt libv8android.so - url("$rootDir/../node_modules/v8-android/dist") + url("$rootDir/../node_modules/v8-android-nointl/dist") } diff --git a/package.json b/package.json index 43476aa..c312a90 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "RN_VERSION": "v0.60.6" }, "dependencies": { - "v8-android": "^7.8.0" + "v8-android": "7.8.x >= 7.8.1" + }, + "peerDependencies": { + "react-native": "^0.60.0" } } diff --git a/src/androidexecutor/reactexecutor/Android.mk b/src/androidexecutor/reactexecutor/Android.mk index f456b33..3805731 100644 --- a/src/androidexecutor/reactexecutor/Android.mk +++ b/src/androidexecutor/reactexecutor/Android.mk @@ -17,6 +17,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE LOCAL_CPP_FEATURES := exceptions LOCAL_STATIC_LIBRARIES := libjsireact libjsi v8runtime -LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libv8 +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libv8android include $(BUILD_SHARED_LIBRARY) diff --git a/src/androidexecutor/reactexecutor/V8Executor.java b/src/androidexecutor/reactexecutor/V8Executor.java index 6ce3e30..aa40586 100644 --- a/src/androidexecutor/reactexecutor/V8Executor.java +++ b/src/androidexecutor/reactexecutor/V8Executor.java @@ -13,8 +13,6 @@ public class V8Executor extends JavaScriptExecutor { static { - // libv8 must be loaded explicitly to invoke its JNI_OnLoad. - SoLoader.loadLibrary("v8"); SoLoader.loadLibrary("v8executor"); } diff --git a/src/patches/build_with_v8.patch b/src/patches/build_with_v8.patch index a604937..c562a77 100644 --- a/src/patches/build_with_v8.patch +++ b/src/patches/build_with_v8.patch @@ -40,7 +40,7 @@ index 0859fcd..0fdff9f 100644 into("$buildDir/react-ndk/exported") exclude("**/libjsc.so") exclude("**/libhermes.so") -+ exclude("**/libv8.so") ++ exclude("**/libv8android.so") } task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) { diff --git a/src/sowrapper/Android.mk b/src/sowrapper/Android.mk index db07957..d245623 100644 --- a/src/sowrapper/Android.mk +++ b/src/sowrapper/Android.mk @@ -1,6 +1,6 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE:= v8 -LOCAL_SRC_FILES := jni/$(TARGET_ARCH_ABI)/libv8.so +LOCAL_MODULE:= v8android +LOCAL_SRC_FILES := jni/$(TARGET_ARCH_ABI)/libv8android.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) diff --git a/src/v8runtime/Android.mk b/src/v8runtime/Android.mk index 504825d..45e1187 100644 --- a/src/v8runtime/Android.mk +++ b/src/v8runtime/Android.mk @@ -19,6 +19,6 @@ ifeq ($(APP_OPTIM),release) LOCAL_CFLAGS += -O3 endif -LOCAL_SHARED_LIBRARIES := libfolly_json libv8 glog +LOCAL_SHARED_LIBRARIES := libfolly_json libv8android glog include $(BUILD_STATIC_LIBRARY) diff --git a/yarn.lock b/yarn.lock index 95fc6a1..48bc09e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,7 +2,7 @@ # yarn lockfile v1 -v8-android@^7.8.0: - version "7.8.0" - resolved "https://registry.yarnpkg.com/v8-android/-/v8-android-7.8.0.tgz#5c95722fe78a8b488563f18a0dab238495cf56ac" - integrity sha512-nBzlNYoCgptxaKlJ7O6miQsF+ctY33Tk+HmqxFDVy29LqEm7Tf13r0al71TYrh1TOu9mHZAEJJTpjdpyN4o0bw== +"v8-android@7.8.x >= 7.8.1": + version "7.8.1" + resolved "https://registry.yarnpkg.com/v8-android/-/v8-android-7.8.1.tgz#2686c3fe655742bbd02e1b6d1c3e336365d4e8e0" + integrity sha512-fxqBNITrILwfzQI9ZIWHR44B6Hvhplfht+V9dpcTrm7CGZjWpUaD/n3C0ghCW15VLRYhWPuCVltXHwbvsBOLjw==