94
votes

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.

20
From v0.60 changelog/blog: With this change, React Native apps will need to begin using AndroidX themselves. They cannot be used side-by-side in one app, so all of the app code and dependency code needs to be using one or the other. This might be a case for you?AsifM

20 Answers

62
votes

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")
    }
40
votes

I've just cleaned the build folder for android and after that, it worked fine. Hope that helps mate.

cd android
./gradlew clean 
24
votes

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.

11
votes
  1. open node_modules/jsc-android/README.md
  2. find section 'How to use it with my react Native app'

for example:

  1. 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()

    }
}
  1. 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
}
10
votes

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 taken from here

8
votes

i have solved this by adding

 configurations.all {
    resolutionStrategy {
        force "com.facebook.soloader:soloader:0.8.2"
    }
}
4
votes

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()
    }
}
4
votes

I did nothing more. ./gradlew clean solved my problem.

3
votes

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()
    }
}
3
votes

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
3
votes

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

2
votes

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
    }
0
votes

In my case, Hermes was never enabled and yet I encountered this error. Cleaning (via Android Studio) and rebuilding resolved the error.

0
votes

Try to replace your ndk object inside app/build.gradle

defaultConfig {
...
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}
0
votes

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

0
votes

It happens to me after I updated my android studio, then I clean and build again, it doesn't crash any more.

0
votes
 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.

-2
votes

In my case, just turn the enableHermes on in app/build.gradle:

project.ext.react = [
    entryFile   : "index.js",
    enableHermes: true,  // HERE!
]
-3
votes

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'
-3
votes

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;