Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hermes emit binary crash #25609

Closed
mjmasn opened this issue Jul 12, 2019 · 45 comments
Closed

Hermes emit binary crash #25609

mjmasn opened this issue Jul 12, 2019 · 45 comments
Labels
Bug Platform: Linux Building on Linux. Stale There has been a lack of activity on this issue and it may be closed soon. Tech: Hermes Hermes Engine: https://hermesengine.dev/

Comments

@mjmasn
Copy link
Contributor

mjmasn commented Jul 12, 2019

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
@kashsbd
Copy link

kashsbd commented Jul 13, 2019

Hello @mjmasn , I face the same error. Do you have solution to generate signed apk with hermes engine without any errors ?

@mjmasn
Copy link
Contributor Author

mjmasn commented Jul 13, 2019

@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.

@paulovlobato
Copy link

@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!

@zeljkoX
Copy link

zeljkoX commented Jul 17, 2019

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?

@react-native-bot react-native-bot added the Tech: Hermes Hermes Engine: https://hermesengine.dev/ label Jul 17, 2019
@giannismacheras
Copy link

@mjmasn I also used your snippet and the problem was fixed, thanks! However, using the Android Studio APK Analyzer, I saw that a file called 'index.android.bundle_temp' is included in the assets directory. I guess this is related to your snippet. What can I do to fix this?

@mjmasn
Copy link
Contributor Author

mjmasn commented Jul 18, 2019

@luckyluke19 hmm, good point, I haven't tried this but probably something like

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

after the hermes command?

Let me know if that works and I'll update my post. I haven't really got time to look at any more switching-to-Hermes stuff in our app at the moment.

@giannismacheras
Copy link

@mjmasn No, it doesn't work. It shows the initial error again (Process 'command '../../node_modules/hermesvm/linux64-bin/hermes'' finished with non-zero exit value 135)

@thinhtran3588
Copy link

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

@giannismacheras
Copy link

@thinhtran3588 thanks, that worked!

@nagaraj95
Copy link

nagaraj95 commented Jul 19, 2019

@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()
            }
        }
    }

`

@valery-lavrik
Copy link

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

what should I do?

@valery-lavrik
Copy link

./gradlew bundleRelease --info

gave such a result:
...

Task :app:bundleReleaseJsAndAssets FAILED
Caching disabled for task ':app:bundleReleaseJsAndAssets' because: Build cache is disabled
...

How to enable cache?

@mjmasn
Copy link
Contributor Author

mjmasn commented Aug 2, 2019

@valery-lavrik see my earlier comments #25601 (comment)

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"
);

@valery-lavrik
Copy link

@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?

@chauhanparth210
Copy link

chauhanparth210 commented Aug 5, 2019

please anyone give solution about it.
(same thing happens to me do all the changes and at the end get error as above)

@valery-lavrik
Copy link

valery-lavrik commented Aug 6, 2019

@mjmasn The solution to my problem is already in the last patch. c21e36d

But during installation, an outdated version is installed for me. Why?
http://prntscr.com/op1q42

@BSoD38
Copy link

BSoD38 commented Aug 6, 2019

@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.

@kashsbd
Copy link

kashsbd commented Aug 15, 2019

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

@valery-lavrik
Copy link

@kashsbd I think so too

@hemmedo
Copy link

hemmedo commented Aug 22, 2019

yeah it still persists.

@adnkh
Copy link

adnkh commented Aug 22, 2019

In my case, the building release with --variant=release is working fine, but making bundle Release for play store is not working the application just crash immediately after the splash screen
This is in 0.60.5

@giannismacheras
Copy link

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

@hemmedo
Copy link

hemmedo commented Aug 22, 2019

@adnkh then why /gradlew assembleRelease isn't working? Technically they're doing the same thing. Nevertheless, I'm just gonna wait for this Hermes update to go live.

@nagaraj95
Copy link

nagaraj95 commented Aug 22, 2019 via email

@giannismacheras
Copy link

@nagaraj95 instead of running ./gradlew bundleRelease to generate an AAB file, I ran ./gradlew assembleRelease and generated APK files. Is that what you mean?

@nagaraj95
Copy link

nagaraj95 commented Aug 22, 2019 via email

@hemmedo
Copy link

hemmedo commented Aug 22, 2019

@luckyluke19 ./gradlew assembleRelease doesnt work for us. What did you do to get it working?

@giannismacheras
Copy link

@hemmedo, @nagaraj95
If you are getting an error about hermes, try this: #25609 (comment)

@aecorredor
Copy link

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

@zeljkoX
Copy link

zeljkoX commented Aug 26, 2019

@aecorredor I haven't.

@rksh1997
Copy link

I am still having this problem with 0.60.5

@TheChanDI
Copy link

having issue for 0.60.4

@yanqiqi1996
Copy link

@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?

I follow you ,it‘s ok in 0.60.5

@valery-lavrik
Copy link

@yanqiqi1996

I follow you ,it‘s ok in 0.60.5

you did it in win10?
I think the problem is in win10.

@vitalyiegorov
Copy link
Contributor

vitalyiegorov commented Sep 2, 2019

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

@LydGol90
Copy link

LydGol90 commented Sep 3, 2019

@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?

@vitalyiegorov
Copy link
Contributor

@LydGol90 absolutely, using mac locally, trying to setup appcenter.ms right now - seems to have successful build there.

@zeljkoX
Copy link

zeljkoX commented Sep 3, 2019

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

@sunnylqm
Copy link
Contributor

This should be fixed in facebook/hermes#45 and will be included in 0.61

@leaky
Copy link

leaky commented Sep 26, 2019

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.

@ammarRajabA
Copy link

@valery-lavrik see my earlier comments #25601 (comment)

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"
);

@mjmasn ,thanks for your contribution, but I have a question, should I move react.gradle back to the node_modules folder where it was because I see same error after the changes.

@mjmasn
Copy link
Contributor Author

mjmasn commented Nov 13, 2019

@ammarRajabA there's a line something like:

apply from: "../../node_modules/react-native/react.gradle"

in android/app/build.gradle

You should update that to point to the new file. Moving the react.gradle back to node_modules would only work temporarily, as it would be overwritten when node_modules are installed.

I haven't tried the latest RN releases with Hermes so I have no idea if these workarounds are still necessary. Would be surprised if it hadn't been fixed by now... 🤔

@ruslan-hontar
Copy link

ruslan-hontar commented Feb 3, 2020

  1. Copy react.gradle from ../../node_modules/react-native/ to ./android/app/
  2. Change apply from: "../../node_modules/react-native/react.gradle" to apply from: "./react.gradle" in android/app/build.gradle
  3. In react.gradle add
def hbcTempFile = file("${jsBundleFile}.hbc")

after def hermesFlags;, change

commandLine(getHermesCommand(), ... )

to

commandLine(getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags)

after exec {...} add

ant.move(
  file: hbcTempFile,
  toFile: jsBundleFile
);
  1. In android/build.gradle/ add
    configurations.all {
        resolutionStrategy {
            force "com.facebook.soloader:soloader:0.8.0"
        }
    }

Now I can upload bundle build to Google Play and it doesn't crash after splash screen.

@stale
Copy link

stale bot commented May 3, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 3, 2020
@stale
Copy link

stale bot commented May 10, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed May 10, 2020
@facebook facebook locked as resolved and limited conversation to collaborators May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Linux Building on Linux. Stale There has been a lack of activity on this issue and it may be closed soon. Tech: Hermes Hermes Engine: https://hermesengine.dev/
Projects
None yet
Development

No branches or pull requests