'React Native - app crashes with custom build type
I've got a react native application, that works fine in Android, in debug and release build types. I want to add a new build type called releaseStaging, so I'm adding this to the app/build.gradle:
android: {
buildTypes: {
releaseStaging {
resValue "string", "CodePushDeploymentKey", '"**something**"'
matchingFallbacks = ['release']
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
... debug and release defined here ...
}
}
I've purposely named the build type "releaseStaging" because from reading around I can see that the react.gradle file does certain things based on the build type containing the word "release".
When I do:
npx react-native run-android --variant=releaseStaging
It builds OK and deploys to the device I'm testing on, but it just crashes on start.
On looking at logcat, I can see that the error is:
2022-01-26 12:26:00.494 4038-4102/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.myapp, PID: 4038
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.mediaburst.timetastic/lib-main flags = 1]
SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/com.mediaburst.timetastic-jFpmTXGDULHlB6h75bUGQA==/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/com.mediaburst.timetastic-jFpmTXGDULHlB6h75bUGQA==/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.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:29)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1066)
at java.lang.Thread.run(Thread.java:919)
Solution 1:[1]
This problem occurs if your app has enableHermes flag set to true
I did not find it documented anywhere, but the solution would be to extend the code like following:
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseStagingImplementation files(hermesPath + "hermes-debug.aar") // Add this line
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
I'm not sure if it should be releaseStagingImplementation or releasestagingImplementation, so try with one or the other.
This tells the Gradle to include Hermes libraries in releaseStaging build type.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aleksandar Nikolic |
