Kudo / react-native-v8

Opt-in V8 runtime for React Native Android
MIT License
922 stars 69 forks source link

How to disable hermes? #59

Closed terfender closed 3 years ago

terfender commented 3 years ago

Hi, I am getting an error cuz of hermes.

2020-11-24 19:57:36.751 30421-30507/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: MYAPP, PID: 30421
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libhermes.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
        at java.lang.System.loadLibrary(System.java:1668)
        at com.swmansion.reanimated.NativeProxy.<clinit>(Unknown Source:2)
        at com.swmansion.reanimated.c.u(Unknown Source:0)
        at com.swmansion.reanimated.d.getJSIModules(Unknown Source:12)
        at com.facebook.react.r.q(Unknown Source:135)
        at com.facebook.react.r.c(Unknown Source:0)
        at com.facebook.react.r$e.run(Unknown Source:68)
        at java.lang.Thread.run(Thread.java:929)

app/build.gradle


project.ext.react = [
  enableHermes: false,  // clean and rebuild if changing
]

def enableHermes = project.ext.react.get("enableHermes", false);

dependencies {
  if (enableHermes) {
      def hermesPath = "../../node_modules/hermes-engine/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
  } else {
      // implementation jscFlavor
      // Add v8-android - prebuilt libv8android.so into APK
      implementation 'org.chromium:v8-android:+'
  }
}

Related packages:

"react-native": "0.63.3",
"react-native-v8": ">=0.63.3-patch.0 <0.63.4",
"v8-android-jit-nointl": "^8.84.0"

Any ideas how to disable it so I can use v8-android-jit-nointl?

Thanks in advance.

dcboy commented 3 years ago

modify android/build.gradle

     maven {
terfender commented 3 years ago

@dcboy already did, but still facing same issue.

allprojects {
  repositories {
    mavenLocal()
    maven {
      // Replace AAR from original RN with AAR from react-native-v8
      url("$rootDir/../node_modules/react-native-v8/dist")
    }
    maven {
      // prebuilt libv8android.so
      url("$rootDir/../node_modules/v8-android-jit-nointl/dist")
    }

    google()
    jcenter()
    maven { url 'https://www.jitpack.io' }
  }
}
Kudo commented 3 years ago

It seems to be related to reanimated2. Since reanimated2 also had a native share library and it may not support V8, I will take a look tomorrow and try to find some solutions.

terfender commented 3 years ago

Thanks @Kudo , confirming I am using reanimated2

"react-native-reanimated": "2.0.0-alpha.7",
Kudo commented 3 years ago

@Terfender From the reanimated2 document, they said only Hermes is supported in the meantime. https://github.com/software-mansion/react-native-reanimated/blob/master/docs/docs/about.md#known-problems-and-limitations

The fact is that reanimated2 requires JSI and shipped with prebuilt AAR and shared libraries - libreanimated.so and libturbomodulejsijni.so. libreanimated.so was built from a Hermes enabled environment and it requires libhermes.so in runtime.

$ /path/to/ndk/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf -d jni/arm64-v8a/libreanimated.so | grep hermes
 0x0000000000000001 (NEEDED)             Shared library: [libhermes.so]

That's why the crash happens when loading libreanimated.so.

The possibly solution would be building from source code and it requires some patch in react-native-reanimated.

terfender commented 3 years ago

Oww. That's unfortunate, but thanks a lot for looking into this. I hope there will be an easy patch for all libs/packages in the future to opt-in v8.

Closing the issue now.

Kudo commented 3 years ago

With more and more C++ native code involved, shipping with prebuilt AAR in react-native is not flexible. Maybe in the future we will all build from source. Otherwise C++ ABI stability is necessary.