14

I'm in the process of migrating a React Native project from react-native version 0.58.5 to 0.60.4.

For the Android part I've done all the changes mentioned here

I let Hermes disabled in my app build.gradle file:

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]
...
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
...
dependencies {
    ...

    if (enableHermes) {
      println 'Hermes is enabled'
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      println 'Hermes is disabled'
      implementation jscFlavor
    }
}
...

I can see the Hermes is disabled print at build time. And this is exactly what I want.

When launching the Android app with react-native run-android I get the following crash at startup :

FATAL EXCEPTION: create_react_context
E  Process: com.reactnativetestapp, PID: 21038
E  java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
E      at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
E      at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
E      at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
E      at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
E      at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
E      at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
E      at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
E      at java.lang.Thread.run(Thread.java:764)

After some research I could see this crash occurs for people wanting to enable Hermes and that has a wrong gradle configuration : [0.60.3] App crash on startup when enabling Hermes (enableHermes: true)

Why am I getting this crash while Hermes is disabled?

Note that when setting enableHermes to true no crash occurs.

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
cjosepha
  • 193
  • 1
  • 1
  • 12

6 Answers6

2

I solved this problem by a tiny change after doing this steps in this article

https://github.com/facebook/react-native/issues/25415

Then make sure to add this jsc-android block to your android/build.gradle:

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

        //THIS ONE
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
    }
}
Shaishav
  • 5,282
  • 2
  • 22
  • 41
C.Yun
  • 29
  • 1
  • Thank you. Been fighting this frustrating issue for a day now and this solved my problem. – Dave Jul 23 '19 at 12:31
  • I'm still experiencing this issue with react-native 0.61.5 and 0.62.2 and the change s you suggest don't seem to solve it...also other commentators on that github issue had problems on same version... – Tadej Jun 17 '20 at 00:21
  • @Tadej did you ever figure out the reason? I'm experiencing the same issue as well – Adonis K. Kakoulidis Jun 25 '20 at 10:56
  • @AdonisK.Kakoulidis I'm not sure, haven't been doing new releases recently so only limited devices tested, but seems like updating soloader might be a solution. I think you should follow this issue: https://github.com/facebook/react-native/issues/25537 Btw, this one wasn't crashing the app btw, so I think it's not a severe issue. – Tadej Jun 26 '20 at 10:42
1

you can use the older version of com.facebook.soloader:soloader by adding configurations.all into your build.gradle

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

like this build.gradle

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

perform below steps if the above steps are not working

app/build.gradle.

android {
  ...
  // add the following packagingOptions 
  packagingOptions {
    pickFirst 'lib/x86_64/libjsc.so'
    pickFirst 'lib/arm64-v8a/libjsc.so'
  }
}

We also added the following to the defaultConfig in the app/build.gradle

ndk {
  abiFilters 'armeabi-v7a', 'x86'
}
Muhammad Numan
  • 23,222
  • 6
  • 63
  • 80
  • Didn't work for me + Google play is complaining because x64 platforms are filtered out. Even with those included, app still crashes with the same error... – Tadej Jun 17 '20 at 00:11
0

I solved this problem by this steps

  1. install hermesvm : npm i hermesvm
  2. install jsc-android : npm i jsc-android

3.add this lines to app/build.gradle

project.ext.react = [
   entryFile: "index.js" ,
   enableHermes: false
]

def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);


dependencies {
   if (enableHermes) {
       def hermesPath = "../../node_modules/hermesvm/android/";
       debugImplementation files(hermesPath + "hermes-debug.aar")
       releaseImplementation files(hermesPath + "hermes-release.aar")
    }
   else { implementation jscFlavor }
  1. add this jsc-android block to your android/build.gradle:
     allprojects {
       repositories {
         maven {
           url("$rootDir/../node_modules/react-native/android")
         }
         maven {
            url "$rootDir/../node_modules/react-native/android"
         }
         google()
         jcenter()
       }
     }
Prateek Thapa
  • 4,829
  • 1
  • 9
  • 23
0

Double-check please all the updates here - https://react-native-community.github.io/upgrade-helper/?from=0.59.9&to=0.60.5

I had the same error, because made a mistake in migration of the android/app/build.gradle file.

denieler
  • 237
  • 3
  • 8
  • I've noticed that issue exists in 0.61.5...I've tried to upgrade to 0.62.2 but still the same. So the issue seems to be version independent that's why I doubt upgrade helper can help. – Tadej Jun 17 '20 at 00:15
0

The errors is generally faced in android 11 users

In your project level build.gradle, Add this snippet

allprojects{
    respositories{
    ...
    google()
    jcenter()
    configurations.all {
        resolutionStrategy {

            // use 0.9.0 to fix crash on Android 11
            force "com.facebook.soloader:soloader:0.9.0"
        }
    }
}
Manish Arora
  • 397
  • 3
  • 12
0

I was facing the same issue in my app for Android 10 users.

I fixed it by changing this

implementation "com.facebook.react:react-native:+" // From node_modules

into

implementation ("com.facebook.react:react-native") version {
        strictly "0.63.2" // pass in your react-native version
}

I have also disabled hermes

project.ext.react = [
    enableHermes: false,
]

And my packagingOptions looks like this,

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude("META-INF/*.kotlin_module")

        pickFirst 'lib/armeabi-v7a/libfbjni.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libfbjni.so'
        pickFirst 'lib/x86_64/libfbjni.so'
        pickFirst 'lib/x86/libfbjni.so'
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
    }
Vibhor
  • 1
  • 2
  • 3