出现“ java.lang.UnsatisfiedLinkError:找不到要加载的DSO:libhermes.so”错误

cjo*_*pha 5 android react-native react-native-hermes

我正在将React Native项目从react-native版本0.58.5迁移到0.60.4。

对于Android部分,我已经完成了此处提到的所有更改

我在我的应用程序build.gradle文件中让爱马仕(Hermes)禁用:

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]
...
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
...
dependencies {
    ...

    if (enableHermes) {
      println 'Hermes is enabled'
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      println 'Hermes is disabled'
      implementation jscFlavor
    }
}
...
Run Code Online (Sandbox Code Playgroud)

我可以Hermes is disabled在构建时看到打印内容。这正是我想要的。

使用react-native run-android启动Android应用程序时,在启动时出现以下崩溃:

FATAL EXCEPTION: create_react_context
                         E  Process: com.reactnativetestapp, PID: 21038
                         E  java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
                         E      at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
                         E      at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
                         E      at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
                         E      at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
                         E      at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
                         E      at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
                         E      at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
                         E      at java.lang.Thread.run(Thread.java:764)
Run Code Online (Sandbox Code Playgroud)

经过一些研究,我发现这种崩溃发生在希望启用Hermes的人身上,并且gradle配置错误:[0.60.3]启用Hermes时启动时应用崩溃(enableHermes:true)

为什么在爱马仕(Hermes)禁用的情况下出现此崩溃?

请注意,设置enableHermestrue无崩溃时会发生。

小智 2

在执行本文中的步骤后,我通过一个微小的更改解决了这个问题

https://github.com/facebook/react-native/issues/25415

然后确保将此 jsc-android 块添加到您的 android/build.gradle 中:

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }

        //THIS ONE
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
    }
}
Run Code Online (Sandbox Code Playgroud)