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

Android with RN 0.67.3 crashes when running custom build type with hermes enabled #33177

Closed
LadislavBohm opened this issue Feb 25, 2022 · 18 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Platform: Android Android applications. Tech: Hermes Hermes Engine: https://hermesengine.dev/

Comments

@LadislavBohm
Copy link

LadislavBohm commented Feb 25, 2022

Description

When you create new RN project running on 0.67.3 and add a custom build type that inherits from release and launch the app it crashes. Does not crash in debug and does not crash when launching the app in release build type (pre-defined).

Version

0.67.3

Output of npx react-native info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 25.48 GB / 47.76 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.3 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version     2021.1.0.0 AI-211.7628.21.2111.8139111
    Visual Studio: 17.0.32014.148 (Visual Studio Community 2022)
  Languages:
    Java: 17.0.1 - C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.67.3 => 0.67.3
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. npx react-native init AwesomeProject
  2. enable hermes engine
  3. in app/build.gradle define custom build type like this:
        staging {
            initWith release
            signingConfig signingConfigs.debug
            applicationIdSuffix ".staging"
            matchingFallbacks =  ['release']
        }

and enable hermes:

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
    bundleInStaging: true, //include JS bundle in staging builds
    devDisabledInStaging: true //disable DEV mode in staging builds
]
  1. Build and try to run the app in staging build type

Snack, code example, screenshot, or link to a repository

Crash in Android Studio:

2022-02-25 01:00:27.863 32152-32152/? E/SoLoader: couldn't find DSO to load: libjscexecutor.so
    	SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.awesomeproject.staging/lib-main flags = 1]
    	SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64 flags = 0]
    	SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
    	SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
    	Native lib dir: /data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64
     result: 0
2022-02-25 01:00:27.878 21175-21175/? E/ssioncontrolle: Unknown bits set in runtime_flags: 0x800000
2022-02-25 01:00:27.882 21175-21175/? E/ssioncontrolle: Not starting debugger since process cannot load the jdwp agent.
2022-02-25 01:00:27.891 32152-32152/? E/SoLoader: couldn't find DSO to load: libhermes-executor-debug.so caused by: dlopen failed: cannot locate symbol "_ZN8facebook6hermes13HermesRuntime11getDebuggerEv" referenced by "/data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64/libhermes-executor-common-debug.so"... result: 0
2022-02-25 01:00:27.897 19539-19576/? E/ExternalAccountType: Unsupported attribute readOnly
2022-02-25 01:00:27.908 32152-32152/? E/SoLoader: couldn't find DSO to load: libhermes-executor-release.so
    	SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.awesomeproject.staging/lib-main flags = 1]
    	SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64 flags = 0]
    	SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
    	SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
    	Native lib dir: /data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64
     result: 0
2022-02-25 01:00:27.911 32152-32152/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.awesomeproject.staging, PID: 32152
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libjscexecutor.so
    	SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.awesomeproject.staging/lib-main flags = 1]
    	SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64 flags = 0]
    	SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
    	SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
    	Native lib dir: /data/app/~~JSLNwb7IlKnxWGWDPiIrbQ==/com.awesomeproject.staging-N3SYkVVNGuwgJimlsN-CtQ==/lib/arm64
     result: 0
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:918)
        at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:740)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:654)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:634)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:582)
        at com.facebook.react.jscexecutor.JSCExecutor.loadLibrary(JSCExecutor.java:24)
        at com.facebook.react.jscexecutor.JSCExecutor.<clinit>(JSCExecutor.java:20)
        at com.facebook.react.jscexecutor.JSCExecutor.loadLibrary(Unknown Source:0)
        at com.facebook.react.ReactInstanceManagerBuilder.getDefaultJSExecutorFactory(ReactInstanceManagerBuilder.java:352)
        at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:319)
        at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:95)
        at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:42)
        at com.awesomeproject.MainApplication.onCreate(MainApplication.java:47)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1208)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6986)
        at android.app.ActivityThread.access$1700(ActivityThread.java:274)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2093)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8010)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
@react-native-bot react-native-bot added Platform: Android Android applications. Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels Feb 25, 2022
@github-actions
Copy link

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@LadislavBohm
Copy link
Author

I did add environment info so I'm not sure what more this bot wants from me 🤔

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Feb 25, 2022
@react-native-bot react-native-bot removed the Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. label Feb 25, 2022
@LadislavBohm
Copy link
Author

I think I found the issue. It got broken because of this commit:

91adb76

so in order for this to work you need to name your build variants including a word "release". What I tried to do then is this:

rename build variant

stagingRelease {
            initWith release
            signingConfig signingConfigs.debug
            applicationIdSuffix ".staging"
            matchingFallbacks =  ['release']
}

rename settings to align with the new name:

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

and

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
    bundleInStagingRelease: true, //include JS bundle in staging builds
    devDisabledInStagingRelease: true //disable DEV mode in staging builds
]

But I still think this is breaking change and probably not the right way to do it. This requires us to change not only name of build variants but also all references to it like CI scripts.

@pmk1c
Copy link

pmk1c commented Feb 25, 2022

Thank you so much for reporting this. We had the same issue and we probably never would have found the solution without this report. ❤️

@cortinico
Copy link
Contributor

But I still think this is breaking change and probably not the right way to do it. This requires us to change not only name of build variants but also all references to it like CI scripts.

You could specify hermesFlagsForVariant and deleteDebugFilesForVariant to customize variant configs.

That gives you full control over variant behavior + you don't need to rename it to stagingRelease anymore.

@LadislavBohm
Copy link
Author

Is this documented somewhere or can you please show an example how to configure staging with adding Release suffix to work in release builds?
This is a breaking change from 0.66.x as it was working and we never had to specify those so IMO it's worth mentioning somewhere, thank you.

@brunoducattii
Copy link

brunoducattii commented Feb 26, 2022

@LadislavBohm i tried your suggestion without success.

Could you please take a look below and help me? Im in a dead end.

def useIntlJsc = false

apply plugin: "com.android.application"

import com.android.build.OutputFile

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/@sentry/react-native/sentry.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation. If none specified and
 *   // "index.android.js" exists, it will be used. Otherwise "index.js" is
 *   // default. Can be overridden with ENTRY_FILE environment variable.
 *   entryFile: "index.android.js",
...

@LadislavBohm
Copy link
Author

@joaotmachado It's a bit hard to read your gradle file, but I don't see anything wrong when I look at it. Are you getting the same error message as me?

Probably post error message too and try to post build.gradle without all those comments so it's easier to read.

@brunoducattii
Copy link

brunoducattii commented Feb 26, 2022

@LadislavBohm i edited my builld.gradle below. And here goes my error:

2022-02-26 11:06:28.641 1657-1657/com.app.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app.app, PID: 1657
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found: needed by /data/app/~~R3RmzM0PSs5cjsK8SfkpXQ==/com.app.app-NG27bssWS3HWJTIklRgEoQ==/lib/arm64/libjscexecutor.so in namespace classloader-namespace result: 0
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:1098)
        at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:914)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:826)
    ...

@LadislavBohm
Copy link
Author

I don't think your problem is related to the same issue I had. The error doesn't even look like you are building staging build type.

Are you building it with "./gradlew.bat assembleStagingRelease"? Seems like you built standard assembleRelease version and that crashed with slightly different error. Not sure I can help here.

@brunoducattii
Copy link

I don't think your problem is related to the same issue I had. The error doesn't even look like you are building staging build type.

Are you building it with "./gradlew.bat assembleStagingRelease"? Seems like you built standard assembleRelease version and that crashed with slightly different error. Not sure I can help here.

@LadislavBohm The error occurs on Debug Mode when executing react-native run-android.

@nawbc
Copy link
Contributor

nawbc commented Mar 11, 2022

I get a similar problem when reloading using flipper, the app will crash

@jackstudd
Copy link

But I still think this is breaking change and probably not the right way to do it. This requires us to change not only name of build variants but also all references to it like CI scripts.

You could specify hermesFlagsForVariant and deleteDebugFilesForVariant to customize variant configs.

That gives you full control over variant behavior + you don't need to rename it to stagingRelease anymore.

Thanks ! Got it resolved by adding these lines in android/app/build.gradle (my variant name's beta) :

project.ext.react = [
    bundleInBeta: true,
    devDisabledInBeta: true,
    hermesFlagsForVariant: {
        def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('beta') ? ['-w'] : []
    },
    deleteDebugFilesForVariant: {
        def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('beta')
    },
]

as mentioned in #32281

@Elitebigboss90
Copy link

This is saver! I wish we can at least have some comments in that build type section so indicate the naming convention

@HyopeR
Copy link

HyopeR commented Apr 20, 2022

What exactly should we do to get rid of this error in this release build? Can someone give an example build.gradle?

@cortinico cortinico added the Tech: Hermes Hermes Engine: https://hermesengine.dev/ label May 10, 2022
@Nehal-Sanklecha
Copy link

It happens with 0.67.4v as well. I think the issue here is that react-native 0.67.4v uses hermes-engine 0.9 instead it should use 0.10. But I'm not sure though.

@glrahulborah
Copy link

glrahulborah commented Nov 25, 2022

> #32281

This worked for me. Thanks

@cortinico
Copy link
Contributor

Closing as this and other variant-related build issues have been fixed in React Native 0.71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention Issues where the author has responded to feedback. Platform: Android Android applications. Tech: Hermes Hermes Engine: https://hermesengine.dev/
Projects
None yet
Development

No branches or pull requests