React-native: New app crashes enabling Hermes on Android emulators with API <= 19

Created on 14 Jul 2019  路  16Comments  路  Source: facebook/react-native

Enabling Hermes in a new app created from scratch, the app crashes at startup on Android x86 emulators from API 16 to 19.

This is the logcat in case of a debug build:

07-14 17:03:50.673 2028-2068/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
java.lang.ExceptionInInitializerError
at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so caused by: Cannot load library: reloc_library[1306]: 1170 cannot locate 'sigemptyset'...

    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
    at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
    at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)聽
    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)聽
    at java.lang.Thread.run(Thread.java:856)

The Release variant shows different errors based on the emulator API level. For example:

  • API 16
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so caused by: Cannot load library: reloc_library[1306]: 1170 cannot locate 'sigemptyset'...
  • API 19
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so caused by: dlopen failed: cannot locate symbol "posix_fallocate" referenced by "libhermes.so"...

The app doesn't crash if API > 19.

React Native version:
System:
OS: macOS 10.14.5
CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Memory: 1.79 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.14.1 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
Android NDK: 20.0.5594570
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.3 => 0.60.3
npmGlobalPackages:
react-native-cli: 2.0.1

Steps To Reproduce

  1. Create a new app:
    react-native init AwesomeProject
  2. Enable Hermes as explained in the guide
  3. Run the app on an Android x86 emulator from API 16 to 19.

Describe what you expected to happen:
the app shouldn't crash.

Snack, code example, or link to a repository:

Bug Hermes Android

Most helpful comment

Hello.

Have you tried using hermes-engine 0.1.1 ?

yarn add hermes-engine --dev

After adding that, you'll have to edit android/app/build.gradle with the following changes:

  1. Enable Hermes (I assume you've done this already), and tell the react compiler where to find the new hermes engine module:
    project.ext.react = [
    entryFile: "index.js",
    enableHermes: true, // clean and rebuild if changing
    hermesCommand: "../../node_modules/hermes-engine/%OS-BIN%/hermes",
    ]

  2. Adjust the dependencies for the new module (replace "hermes-vm" with "hermes-engine"):

    if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
    implementation jscFlavor
    }

I personally don't have any Android 4.4 device for testing. However, a couple of days ago I submitted an app with RN 0.60.5 + Hermes, and the Google Play Pre-launch Report ran it in an Android 4.3 device with no problems whatever.

Cheers!

All 16 comments

Similar Error when I update from react native 0.60 to 0.60.3

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

react native info

System:
    OS: Windows 10
    CPU: (4) x64 Intel(R) Core(TM) i3-7100 CPU @ 3.90GHz
    Memory: 1.09 GB / 7.91 GB
  Binaries:
    Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
    Watchman: 4.9.0 - C:\Shortcut\watchman.EXE
  SDKs:
    Android SDK:
      Android NDK: 15.2.4203891
  IDEs:
    Android Studio: Version  3.4.0.0 AI-183.6156.11.34.5522156

similar issue app builds successfully tries to load a module from the metro bundle but crashes on startup.

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

RN 0.60.4 with Hermes enabled

FATAL EXCEPTION: create_react_context
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so caused by: dlopen failed: cannot locate symbol "posix_fallocate" referenced by "libhermes.so"...
    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
    at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
    at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
    at java.lang.Thread.run(Thread.java:841)

Any news on this?

Guys, had the same issue, but after a while double-checked migration guide https://react-native-community.github.io/upgrade-helper/?from=0.59.9&to=0.60.5 and realized I've made a mistake in android/app/build.gradle, so please double-check your code

@denieler yes, after copying the code from 0.60.4/0.60.5 my app works again without any issues. Although.. it is complaining about Gradle 6 when i react-native run-android.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

Happens the same for you?

@msqar no, this one is not happening for me if I'm not mistaken

Android 4.4
ReactNative 0.60.5

Creating a fresh app with "react-native init" and enabling hermes in android/app/build.gradle:80 still results in this crash when running the debug variant.

Running with "react-native run-android --variant=release" causes the "java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so caused by: dlopen failed: cannot locate symbol "posix_fallocate" referenced by "libhermes.so" crash.

Hello.

Have you tried using hermes-engine 0.1.1 ?

yarn add hermes-engine --dev

After adding that, you'll have to edit android/app/build.gradle with the following changes:

  1. Enable Hermes (I assume you've done this already), and tell the react compiler where to find the new hermes engine module:
    project.ext.react = [
    entryFile: "index.js",
    enableHermes: true, // clean and rebuild if changing
    hermesCommand: "../../node_modules/hermes-engine/%OS-BIN%/hermes",
    ]

  2. Adjust the dependencies for the new module (replace "hermes-vm" with "hermes-engine"):

    if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
    implementation jscFlavor
    }

I personally don't have any Android 4.4 device for testing. However, a couple of days ago I submitted an app with RN 0.60.5 + Hermes, and the Google Play Pre-launch Report ran it in an Android 4.3 device with no problems whatever.

Cheers!

THANK YOU @jsaraiva !

@jsaraiva Does it not work on hermes-engine 0.2.1 which is the current latest?

@jsaraiva Does it not work on hermes-engine 0.2.1 which is the current latest?

Personally, I haven't tested it yet (busy with other projects). But I see no reason why it shouldn't.
I only mentioned the version because version 0.1.0 was still hermes-vm, which was the component causing problems; hermes-engine itself actually started at 0.1.1.
Note that the "yarn add hermes-engine --dev" command I posted did not mention the version.

Cheers!

Yes.. So 0.2.1 got installed. But it did not work for me. Anyways thanks.
Turned off the hermes option for now. App is working fine

Have you tried specifying the older version specifically? (in package.json, specifying
"hermes-engine": "0.1.1"
instead of
"hermes-engine": "^0.2.1"
and running yarn again)

Maybe the devs introduced some new bugs into the engine. It happens.

This same error is happening to me on Android Devices running Android 10 (Pixel 4, for example).
I tried the solution proposed above but got the following error after cleaning and trying to build:

> A problem occurred starting process 'command '../../node_modules/hermes-engine/osx-bin/hermes''

When I check node_modules I don't see hermes inside osx-bin. What happened here? Where should I point the path to?

I am using hermes-engine: 0.6.0

Screenshot of folder of hermes-engine: 0.6.0:

Screenshot 2020-08-11 at 00 06 28

EDIT it seems this only works with hermes-engine: 0.1.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

despairblue picture despairblue  路  3Comments

grabbou picture grabbou  路  3Comments

josev55 picture josev55  路  3Comments

janmonschke picture janmonschke  路  3Comments

DreySkee picture DreySkee  路  3Comments