react-native: Hermes emit binary crash

When running with --variant release or doing a production build, the Hermes emit binary step fails, leaving a 0 byte bundle file. It looks like something to do with overwriting the same file, as if I cancel the build before the hermes step, then manually run the command from the Program arguments below but with a different output path, it works fine and the bytecode bundle is saved correctly.

Stack dump:
0.	Program arguments: ../../node_modules/hermesvm/linux64-bin/hermes -emit-binary -out /REDACTED/android/app/build/generated/assets/react/release/index.android.bundle /REDACTED/android/app/build/generated/assets/react/release/index.android.bundle -O -output-source-map 
1.	Program arguments: ../../node_modules/hermesvm/linux64-bin/hermes -emit-binary -out /REDACTED/android/app/build/generated/assets/react/release/index.android.bundle /REDACTED/android/app/build/generated/assets/react/release/index.android.bundle -O -output-source-map 
[0x41ba83]
[0x41abc9]
[0x41ac6c]
[0x4265e0]
[0x499f43]
[0x49a163]
[0x43d7ff]
[0x43d967]
[0x44003a]
[0x4399b2]
[0x439b32]
[0x42b8b9]
[0x4308d6]
[0x40487b]
[0x712f34]
[0x7131b1]
[0x408116]
[0x41ba83]
[0x41abc9]
[0x41ac6c]
[0x4265e0]
[0x499f43]
[0x49a163]
[0x43d7ff]
[0x43d967]
[0x44003a]
[0x4399b2]
[0x439b32]
[0x42b8b9]
[0x4308d6]
[0x40487b]
[0x712f34]
[0x7131b1]
[0x408116]

FAILURE: Build failed with an exception.

* Where:
Script '/REDACTED/android/app/react.gradle' line: 150

* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command '../../node_modules/hermesvm/linux64-bin/hermes'' finished with non-zero exit value 135

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 57s

React Native version:

System:
    OS: Linux 4.15 Ubuntu 16.04.6 LTS (Xenial Xerus)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
    Memory: 2.09 GB / 15.54 GB
    Shell: 4.3.48 - /bin/bash
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.16.0 - /usr/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    Android SDK:
      API Levels: 22, 24, 26, 27, 28, 29
      Build Tools: 23.0.1, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3, 29.0.0
      System Images: android-22 | Google APIs Intel x86 Atom_64, android-24 | Google APIs ARM 64 v8a, android-24 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom_64, android-24 | Google Play Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64
      Android NDK: 17.1.4828580
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: ^0.60.3 => 0.60.3 
  npmGlobalPackages:
    create-react-native-app: 2.0.2
    react-native-cli: 2.0.1
    react-native-create-library: 3.1.2
    react-native-git-upgrade: 0.2.7

Steps To Reproduce

  1. Try creating a Hermes-enabled release build
  2. đŸ’„

Describe what you expected to happen: The build to succeed.

Snack, code example, or link to a repository: Any new RN 0.60.3 app, but I made an example at https://github.com/mjmasn/HermesApp

  1. Clone the repo
  2. Run yarn
  3. Run yarn start
  4. In a second terminal window run react-native run-android --variant release
  5. Build fails

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 28
  • Comments: 45 (7 by maintainers)

Most upvoted comments

@valery-lavrik see my earlier comments https://github.com/facebook/react-native/issues/25601#issuecomment-510856047

NB this was a quick temporary workaround so I could test out Hermes, the RN / Hermes team need to fix this properly.

  1. Copy react.gradle from node_modules/react-native to android/app
  2. In the copied react.gradle Replace the line starting commandLine(getHermesCommand(),... with:
ant.move(
    file: jsBundleFile,
    tofile: "${jsBundleFile}_temp"
);
commandLine(getHermesCommand(), "-emit-binary", "-out", jsBundleFile, "${jsBundleFile}_temp", *hermesFlags)

Below this (outside the exec section around commandLine(getHermesCommand(),...) add this:

ant.delete(
    file: "${jsBundleFile}_temp"
);

@B4UGUYS see the last code snippet on this https://github.com/facebook/react-native/issues/25601#issuecomment-510856047

You’ll need to copy react.gradle from node_modules to your android/app folder before editing it.

Replace the line starting commandLine(getHermesCommand() with my snippet.

I think this issue is still on react native version 0.60.5 .

@zeljkoX @vitalyiegorov I am seeing the same issue as you, I use circleci. I have tried various ways to reduce java heap size and such and it doesn’t seem to be related to that. The only difference I can see for me is that locally I run on mac OS and in circleci I use the an android-node docker image. I assume that means that locally it uses ‘node_modules/hermesvm/osx-bin/hermes’ whereas on circleci uses ‘node_modules/hermesvm/linux64-bin/hermes’ so I’m guesssing the issue is related to that. Was wondering whether you guys are also building on mac locally?

This should be fixed in https://github.com/facebook/hermes/issues/45 and will be included in 0.61

Same error building with gitlab-ci, locally works perfectly, rn 0.60.5

For me, everything works locally but executing it on CI results in a reported error. Maybe memory issues with CI.

Can Hermes memory usage, number of daemons/threads, can be limited?

@LydGol90 Also, using mac locally, docker image for android on CircleCI.

I am still having this problem with 0.60.5

@zeljkoX same thing happens to me. Runs fine locally but crashes running on CircleCI. Did you find a fix?

@valery-lavrik this is because the commit you’ve linked is available in the latest master, but is not yet available in the stable releases.

A new release containing this fix should be available soon enough.

@mjmasn
I copied the react.gradle file and made changes to it: image and image but command .\gradlew clean and .\gradlew --info bundleRelease still return an error: image why?

@reactjs-bot @react-native-bot @mjmasn i have followed the above steps but I get an error like this

Process ‘command ‘
\node_modules\hermesvm\win64-bin\hermes’’ finished with non-zero exit value -1073741515 Please post some solution for this.Below I posted my react.gradle file

` if (enableHermes) { doLast { def hermesFlags; exec { // if (targetName.toLowerCase().contains(“release”)) { if (!targetName.toLowerCase().contains(“debug”)) { // Can’t use ?: since that will also substitute valid empty lists hermesFlags = config.hermesFlagsRelease if (hermesFlags == null) hermesFlags = [“-O”, “-output-source-map”] } else { hermesFlags = config.hermesFlagsDebug if (hermesFlags == null) hermesFlags = [] } commandLine(getHermesCommand(), “-emit-binary”, “-out”, jsBundleFile, jsBundleFile, *hermesFlags) } if (hermesFlags.contains(“-output-source-map”)) { ant.move( // Hermes will generate a source map with this exact name // NOTE: name coincides with jsOutputSourceMapFile file: “${jsBundleFile}.map”, tofile: jsCompilerSourceMapFile ); exec { // TODO: set task dependencies for caching

                        // Set up the call to the compose-source-maps script
                        workingDir(reactRoot)
                        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                            commandLine("cmd", "/c", *nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile)
                        } else {
                            commandLine(*nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile)
                        }
                    }
                }
            }
        } else {
            doLast {
                ant.move(
                    file: jsPackagerSourceMapFile,
                    tofile: jsOutputSourceMapFile
                );
            }
        }   
 def isRelease = !targetName.toLowerCase().contains("debug")

    def libDir = "$buildDir/intermediates/transforms/"
    def vmSelectionAction = {
        fileTree(libDir).matching {
            if (enableHermes) {
                // For Hermes, delete all the libjsc* files
                include "**/libjsc*.so"

                if (isRelease) {
                    // Reduce size by deleting the debugger/inspector
                    include '**/libhermes-inspector.so'
                    include '**/libhermes-executor-debug.so'
                } else {
                    // Release libs take precedence and must be removed
                    // to allow debugging
                    include '**/libhermes-executor-release.so'
                }
            } else {
                // For JSC, delete all the libhermes* files
                include "**/libhermes*.so"
            }
        }.visit { details ->
            def targetVariant = ".*/transforms/[^/]*/${targetPath}/.*"
            def path = details.file.getAbsolutePath().replace(File.separatorChar, '/' as char)
            if (path.matches(targetVariant) && details.file.isFile()) {
              details.file.delete()
            }
        }
    }

`

If you’re building your android app using RN 0.60. x on CircleCI and Linux, you can set enableHermes: false in android/app/build.gradle:80 to disable the Hermes JS engine and prevent this error until the issue is patched by FB.

@aecorredor I haven’t.

@adnkh Exactly the same thing happened to me. I uploaded APKs instead and the problem was fixed.

I have a similar error: image without text “finished with non-zero exit value”

what should I do?

@LuckyLuke19 you should move it outside exec. Have the same issue and got it work by moving it outside.

@B4UGUYS see the last code snippet on this #25601 (comment)

You’ll need to copy react.gradle from node_modules to your android/app folder before editing it.

Replace the line starting commandLine(getHermesCommand() with my snippet.

Thank you @mjmasn I was having the same issue, your snipped did the trick!