124

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.

V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
  • From [v0.60 changelog/blog](https://facebook.github.io/react-native/blog/2019/07/03/version-60#androidx-support): 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 Jul 23 '19 at 18:42
  • related https://stackoverflow.com/questions/60054822/react-native-0-61-5-crashlytics-missing-libhermes-so-soloader-java-com-facebook – 0xcaff May 01 '20 at 07:22

25 Answers25

66

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")
    }
Vinzzz
  • 11,746
  • 5
  • 36
  • 42
  • 28
    This did not work for me after upgrade to 0.60.4. I tried clean multiple times. I cannot seem to disable hermes. I get crash on start "couldn't find DSO to load: libhermes.so" – Ed of the Mountain Aug 07 '19 at 19:11
  • 3
    Make sure in the src/android/build.gradle, you've also added the maven repo for hermes libs (like the other answer proposes). It might be related to JavaScriptCore & not Hermes specifically – Vinzzz Aug 08 '19 at 21:58
  • Thank you! I was missing "maven { url("$rootDir/../node_modules/jsc-android/dist") } – Ed of the Mountain Aug 11 '19 at 13:57
  • Thank !! Its working form me but don't forget to add this block in project build.gradle maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } – Vishal Gadhiya Sep 16 '19 at 13:05
  • 4
    In react-native 0.61 the hermesvm part in android/app/build.gradle has moved to hermes-engine: https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L186 – Mike Hardy Sep 26 '19 at 13:04
  • this is the updated patch for issue https://github.com/facebook/react-native/issues/24261#issuecomment-548149232 as the hermesvm is moved – Madhu Kumar Nov 11 '19 at 06:44
  • this answer is mixing JSC and hermes together. You can use Hermes or JSC, not both at the same time. The "Also, make sure the Hermes Maven repo is in your root build.gradle" edit therefore makes no sense. – vonovak Jun 03 '20 at 11:47
  • Because this answer does not make assumptions on wether you enabled hermes, or not. Correct paths must be provided for both cases, and these paths did change during RN updates. Anyone can play with that `enableHermes` option – Vinzzz Jun 03 '20 at 12:30
47

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

cd android
./gradlew clean 
samernady
  • 841
  • 7
  • 7
24

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.

skang
  • 265
  • 2
  • 2
16

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

Andru
  • 5,954
  • 3
  • 39
  • 56
  • 5
    After implement still have this issue---> couldn't find DSO to load: libhermes.so SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.tootitoo.tootitoo/lib-main flags = 1] SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/com.tootitoo.tootitoo-1/lib/arm flags = 0] SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/vendor/lib flags = 2] SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib flags = 2] Native lib dir: /data/app/com.tootitoo.tootitoo-1/lib/arm result: 0 – Kyo Kurosagi Aug 11 '20 at 08:27
15
  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
}
Starryi
  • 151
  • 1
  • 4
  • i have performed above way without using packagingOptions and that's enough. Thanks. – oguzhan Apr 23 '20 at 20:50
  • 1
    For me, I just needed to add `pickFirst '**/libjsc.so' pickFirst '**/libc++_shared.so'` – dazza5000 Jul 23 '20 at 18:31
  • Long time research to find the answer. Thanks for the solution. – R.Mohanraj Aug 05 '20 at 14:30
  • OMFG I would upvote this answer a billion @#$%ing times if I could!! I thought I was losing my mind for hours; tried all the above answers' suggestions and adding the **second** maven repo link finally solved it! Having just one or the other **is not enough**. TYSM! :D – Kenny83 Sep 24 '21 at 02:22
  • This is my only solution. – hong developer Sep 28 '21 at 03:59
8

i have solved this by adding

 configurations.all {
    resolutionStrategy {
        force "com.facebook.soloader:soloader:0.8.2"
    }
}
dasl
  • 426
  • 7
  • 6
  • Where exactly did you add this and in which file? – Andru Jul 16 '20 at 10:53
  • 1
    `app/build.gradle` inside end of `dependencies { }` `dependencies { implementation project(':react-native-permissions') configurations.all { resolutionStrategy { force "com.facebook.soloader:soloader:0.8.2" } } }` – dasl Jul 18 '20 at 06:28
5

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
    }
Piotr Badura
  • 1,574
  • 1
  • 13
  • 17
4

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()
    }
}
Eliezer Steinbock
  • 4,728
  • 5
  • 31
  • 43
  • 1
    i just added url("$rootDir/../node_modules/jsc-android/dist") in project gradle. thank you Eliezer Steinbock – Guru Apr 04 '20 at 10:24
4

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
Henrik
  • 1,078
  • 1
  • 9
  • 17
  • Although this is not a permanent solution, it's a temporary work-around that fixed the issue for me for now. Thanks! – Kent Robin Feb 08 '20 at 21:20
3

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()
    }
}
Abhinav Saxena
  • 1,990
  • 2
  • 24
  • 55
kishan verma
  • 984
  • 15
  • 17
3

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

Jack Ou
  • 97
  • 4
  • 1
    ince you are formally posting an answer to an older question. It would be most helpful that you support your purported answer with some code and the output that results from using your code. You can support your answer with a copy and paste or even a screen print if the result from your code cannot be copied. – Gray Sep 24 '20 at 21:06
3

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

michael_vons
  • 875
  • 1
  • 8
  • 16
  • In my case I was missing a `releaseImplementation 'com.facebook.soloader:soloader:0.9.0+'` – SkyzohKey Jun 09 '21 at 03:32
  • 1
    @michael_vons Thank you for the solution. For anyone where it seems it stops working out of nowhere, it would build in Android studio no problem, and react-native run-android will work for API's below 30, but for 30 and up I needed to add the `implementation'com.facebook.soloader:soloader:0.9.0+'` like Michael said and follow the rest of his instructions to get it to build with react-native. Also, having logcat open in Android studio while building/launching a react-native app allowed me to find the issue since metro wasn't spitting out any errors and the app was crashing on build immediately. – Scott K. Jun 17 '21 at 06:09
1

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

not_fubar_yet
  • 194
  • 15
1

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
    }
    ...
}
Simon Bengtsson
  • 7,573
  • 3
  • 58
  • 87
0

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

Isaac Overacker
  • 1,385
  • 10
  • 22
0

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

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

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

Sir Codesalot
  • 7,045
  • 2
  • 50
  • 56
0

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

Elan
  • 131
  • 8
0
 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.

Dhaval Panchani
  • 329
  • 2
  • 8
0

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
tryp
  • 1,120
  • 20
  • 26
0

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
}
Vibhor
  • 1
  • 2
  • 3
0

For me, what did the trick was to add

hermesEnabled=true

in android/gradle.properties

radu122
  • 2,865
  • 24
  • 24
-2

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

project.ext.react = [
    entryFile   : "index.js",
    enableHermes: true,  // HERE!
]
lfree
  • 1,880
  • 3
  • 24
  • 39
  • If you turn on Hermes you just change builds options and it will replace SoLoader to Hermes and make build via Hermes... but it is not fixed – Lukáš Šálek Oct 07 '20 at 07:50
-3

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;
Moaz Khan
  • 1,272
  • 1
  • 13
  • 28
  • Warning! Don't add that import in case you're using the Expo bare workflow. It will mess up the `BuildConfig.DEBUG` value and make your debug builds not work anymore. – Andru Jul 23 '20 at 06:49
  • BuildConfig is a file generated automatically for your project, you shouldn't import the one from facebook. – Bruno Lemos Nov 24 '20 at 00:03
-5

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'
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Chaurasia
  • 494
  • 1
  • 6
  • 22
  • 7
    It is too simple I think!! – Hani Sep 13 '19 at 07:34
  • @Chaurasia what did you do to solve this problem? what are the lines that solved this? – Kruupös Feb 04 '20 at 13:44
  • @Kruupös I'm showing only my file instruction. this file is working a good way. can user match own files to my file? so simple. – Chaurasia Feb 04 '20 at 19:13
  • 3
    @Chaurasia not really, I have some specific config that wouldn't match your requirements.A real answer would be to understand what precise line are causing or solving the issue. I don't even know your React version, so not that simple. – Kruupös Feb 05 '20 at 08:56