Reputation: 7333
I have just updated my project to use react-native version 0.60.2 . But when I am trying to run an application on Android device it gets crashed after launch screen. I got the following error logs :
E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.tjspeed, PID: 3909
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:760)
Few suggestions available here : https://github.com/facebook/react-native/issues/25601 but unfortunately none of them worked for me. Please suggest the workaround.
Upvotes: 130
Views: 94056
Reputation: 2965
For me, what did the trick was to add
hermesEnabled=true
in android/gradle.properties
Upvotes: 0
Reputation: 8161
For us the issue was that 0.68.x of react native didn't support the minSdkVersion we had. We had it set to 26 while react native 0.68 required it to be 21.
Instead of lowering it to 21 we added this config to the app/build.gradle file as outlined in this issue.
android {
...
packagingOptions {
jniLibs.useLegacyPackaging = true
}
...
}
Upvotes: 2
Reputation: 387
I fixed it by making changes in the implementation of react-native in build.gradle file.
By default, it was like this
implementation "com.facebook.react:react-native:+" // From node_modules
I changed it to,
implementation ("com.facebook.react:react-native") version {
strictly "0.63.2" // pass in your react-native version
}
Upvotes: 0
Reputation: 362
this combination worked for me.
in app/build.gradle
disabled hermes.
project.ext.react = [
enableHermes: false,
...
]
and forced rn version.
dependencies {
implementation ("com.facebook.react:react-native") version {
strictly "0.66.4" //<-- your version here
}
...
}
and ./gradlew clean
Upvotes: 2
Reputation: 1120
To avoid this kind of unexpected behavior I've made the choice to use fastlane for all my projects (pretty easy to implement and use). I've created a short lane to clear the project every time I'm looking for a new release.
lane :clean do
gradle(
task: "clean"
)
end
I'm then using this lane on my production lane command
lane :release do
check_env
bump
...
clean
gradle(
task: 'bundle',
build_type: 'Release'
)
end
Upvotes: 0
Reputation: 1672
In my case I needed to add hermes path for each android flavour
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
qaImplementation files(hermesPath + "hermes-release.aar")
stageImplementation files(hermesPath + "hermes-release.aar")
prodImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
Upvotes: 5
Reputation: 405
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
&
Make sure you've installed this - https://www.npmjs.com/package/jsc-android
In my case, it was not there because of some reason.
Upvotes: 0
Reputation: 1060
This is because SOLoader is absent.
Ensure
implementation'com.facebook.soloader:soloader:0.9.0+'
is added under dependencies in android/app/build.gradlle
clean your build
cd android
./gradlew clean
Try bundling
./gradlew bundleRelease
Exit android folder
cd ../
Try running
npx react-native run-android --variant=release
Upvotes: 3
Reputation: 6204
In case you're facing this error while updating to React Native version 0.62.2
:
Add the following to your android/app/build.gradle
file:
dependencies {
implementation 'com.facebook.soloader:soloader:0.9.0+'
as one of the first implementation
entries.
Upvotes: 17
Reputation: 161
It happens to me after I updated my android studio, then I clean and build again, it doesn't crash any more.
Upvotes: 0
Reputation: 1352
If any one is still facing the issue even after applying trying all the steps above then here is the solution
In the MainApplication.java, add this import:
import com.facebook.react.BuildConfig;
Upvotes: -3
Reputation: 151
for example:
allprojects {
repositories {
maven {
// All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Local Maven repo containing AARs with JSC library built for Android
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()
}
}
android {
packagingOptions {
pickFirst '**/libjsc.so'
pickFirst '**/libc++_shared.so'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.webkit:android-jsc:+"
implementation "com.facebook.react:react-native:+" // From node_modules
}
Upvotes: 15
Reputation: 7293
I had this error when I was trying to run with an older version of React Native, prior to 0.60 while in the package.json
had a newer version defined (post 0.60).
Upvotes: 0
Reputation: 432
i have solved this by adding
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
Upvotes: 7
Reputation: 21
Try to replace your ndk object inside app/build.gradle
defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
Upvotes: 0
Reputation: 1158
After following all advise without success I built an *.apk instead of an *.aab. The APK is 16 MB as opposed to the 8 MB AAB, but I finally got rid of the UnsatisfiedLinkError.
To build an AAB (crashed with UnsatisfiedLinkError):
cd android && ./gradlew clean && ./gradlew bundleRelease
To build an APK (no crash and hermes works fine too):
cd android && ./gradlew clean && ./gradlew assembleRelease
Upvotes: 4
Reputation: 838
I've just cleaned the build folder for android and after that, it worked fine. Hope that helps mate.
cd android
./gradlew clean
Upvotes: 46
Reputation: 1535
In my case, Hermes was never enabled and yet I encountered this error. Cleaning (via Android Studio) and rebuilding resolved the error.
Upvotes: 0
Reputation: 2216
In my case, just turn the enableHermes
on in app/build.gradle
:
project.ext.react = [
entryFile : "index.js",
enableHermes: true, // HERE!
]
Upvotes: -2
Reputation: 1000
Add this in your project level gradle
allprojects {
repositories {
maven {
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenLocal()
google()
jcenter()
}
}
Upvotes: 3
Reputation: 5098
For others that run into this issue, there are 2 sections that look similar. You need to update the bottom repositories
section in android/build.gradle
!
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
Upvotes: 4
Reputation: 496
Solve this problem in a simple way.
apply plugin: "com.android.application"
// def useIntlJsc = false
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
bundleInStaging: true, // Add this
bundleInInternalTest: true, // Add this
bundleInRelease: true
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.inbox.clean.free.gmail.unsubscribe.smart.email.fresh.mailbox"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2597205 //4242929
versionName "1.6.3"
multiDexEnabled true
ndk {
// abiFilters "armeabi-v7a", "x86"
// abiFilters.clear()
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
shrinkResources enableSeparateBuildPerCPUArchitecture
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
project.ext.sentryCli = [
logLevel: "debug",
flavorAware: false,
//add
enableHermes: false
]
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
splits {
abi {
reset()
enable true
universalApk false // If true, also generate a universal APK
include "armeabi-v7a","arm64-v8a","x86","x86_64"
//"armeabi-v7a" "arm64-v8a" "x86" "x86_64"
// include "armeabi-v7a", "x86"
exclude "ldpi", "xxhdpi", "xxxhdpi"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a":3,"x86_64":4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-linear-gradient')
implementation fileTree(dir: "libs", include: ["*.jar"])
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
Upvotes: -5
Reputation: 11724
I had the same issue after upgrading from 0.59.8 to 0.60.4
Make sure you have added all these lines in your app/build.gradle, especially the dependencies part as this makes sure you have JSC binary
project.ext.react = [
...
// your index js if not default, other settings
// Hermes JSC ?
enableHermes: false,
...
]
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
if (enableHermes) {
// For RN 0.60.x
def hermesPath = "../../node_modules/hermesvm/android/"
// --- OR ----
// for RN 0.61+
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
EDIT
Also, make sure the Hermes Maven repo is in your root build.gradle
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
Upvotes: 65
Reputation: 265
I added this block in allProject block in project_dir/build.gradle and the crash went away.
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
What I did is to create new project with react-native init and went through the android build files. Fortunately this one was the first difference I noticed and fixed my issue. I guess you could do the same if this doesn't work.
Upvotes: 24