React-Native :java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
AndroidReact NativeAndroid Problem Overview
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.
Android Solutions
Solution 1 - Android
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")
}
Solution 2 - Android
I've just cleaned the build folder for android and after that, it worked fine. Hope that helps mate.
cd android
./gradlew clean
Solution 3 - Android
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.
Solution 4 - Android
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.
Solution 5 - Android
- open node_modules/jsc-android/README.md
- find section 'How to use it with my react Native app'
for example:
- modify android/build.gradle
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()
}
}
- modify android/app/build.gradle
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
}
Solution 6 - Android
i have solved this by adding
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
Solution 7 - Android
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()
}
}
Solution 8 - Android
I did nothing more. ./gradlew clean
solved my problem.
Solution 9 - Android
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
Solution 10 - Android
> 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()
}
}
Solution 11 - Android
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
Solution 12 - Android
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
}
Solution 13 - Android
In my case, Hermes was never enabled and yet I encountered this error. Cleaning (via Android Studio) and rebuilding resolved the error.
Solution 14 - Android
Try to replace your ndk object inside app/build.gradle
defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
Solution 15 - Android
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).
Solution 16 - Android
It happens to me after I updated my android studio, then I clean and build again, it doesn't crash any more.
Solution 17 - Android
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.
Solution 18 - Android
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
Solution 19 - Android
In my case, just turn the enableHermes
on in app/build.gradle
:
project.ext.react = [
entryFile : "index.js",
enableHermes: true, // HERE!
]
Solution 20 - Android
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;
Solution 21 - Android
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'