40

I have been trying to add ReactNative to my existing android application. I followed the instructions from this link. I could add it but the app gets crashed once I open the react native activity. I have started server using

adb reverse tcp:8081 tcp:8081

and started react-native using

react-native start

I get a dialogue that the js files are loading. But finally end up with a crash. Following is the error that is being printed in logcat:

java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libreactnativejni.so
    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:213)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:178)
    at com.facebook.react.bridge.JSCJavaScriptExecutor.<clinit>(JSCJavaScriptExecutor.java:19)
    at com.facebook.react.ReactInstanceManager.onJSBundleLoadedFromServer(ReactInstanceManager.java:413)
    at com.facebook.react.ReactInstanceManager.createReactContextInBackground(ReactInstanceManager.java:236)

I am completely lost as I am unable to figure out the cause for this issue.

Thanks in advance.

Arnold Schrijver
  • 3,588
  • 3
  • 36
  • 65
Anudeep
  • 1,520
  • 1
  • 19
  • 38
  • But you **do** have the .so file in your project? it's (in theory) linked correctly? – Grisgram Apr 12 '17 at 12:38
  • No. I didn't add any of it. – Anudeep Apr 13 '17 at 04:01
  • I have the same problem. Since @Anu there have been some changes in the stacktrace, but the error is the same. Deeper on the stacktrace I find it comes from: `at com.example.MainActivity.onCreate(MainActivity.java:44)` which is very strange, because line 44 is the end of the file, not `onCreate` method. Using RN 0.46.4 – Arnold Schrijver Aug 11 '17 at 06:31
  • It's interesting to see so many people having this problem in their local. I could only get this in Production, through Crashlytics. – Hung Vu Dec 13 '22 at 04:34

11 Answers11

38

actually in my case these steps worked:

  1. uninstall the app from the device
  2. close Metro Bundler
  3. run ./gradlew clean on android directory
  4. run react-native run-android

hope to help you.

Ahmad Khani
  • 850
  • 2
  • 10
  • 15
22

This has fixed my issue :

   ndk {
        abiFilters 'armeabi-v7a', 'x86'
    }

This should be placed build.gradle defaultConfig section.

Amir Hedieh
  • 1,120
  • 1
  • 14
  • 28
Aristo Michael
  • 2,166
  • 3
  • 35
  • 43
  • 1
    Tnx man! you saved me!! but also a question. does adding this code has any side-effects? i mean if solution was this easy why React-Native team didn't put this in their code? – Amir Hedieh Feb 18 '19 at 14:33
  • @Amas I don't know is was your case but I got this problem because someone deletes this section in the code. :) – BlaShadow Mar 23 '19 at 12:43
  • It was removed by React team; `react-native upgrade` command overwrite old version with one without ndk. – Alex Shtromberg May 13 '19 at 06:54
  • 1
    Can confirm that this no longer works as of react-native `0.65` – Hung Vu Dec 13 '22 at 04:35
15

This is caused by the following issue (open for 2 years) https://github.com/facebook/react-native/issues/2814

From the issue:

React Native on Android doesn't provide a 64-bit version of the libreactnativejni.so native library, which can cause compatibility issues on 64-bit devices. I ran into this while attempting to integrate React Native with a large existing application I'm developing.

Reaction from Facebook:

"Thanks for reporting! Yes we don't provide 64-bit version of the native code and the system should always fall back to 32-bit."

And:

"Most Android projects use a number of 3rd-party libraries, and any that include native 64-bit code will cause React Native to fail."

The following SO answer Use 32-bit jni libraries on 64-bit android explains fallback to 32-bit libraries and the fact you cannot mix. So if 64-bit is found, all should be 64-bit

I suggest reading along the Github issue #2814. There are multiple fixes proposed, but it depends on your situation what works.

The issuer has also written a blog about it: Mixing 32- and 64-bit Dependencies in Android

Hope this helps!

Community
  • 1
  • 1
Arnold Schrijver
  • 3,588
  • 3
  • 36
  • 65
  • 1
    PS @Anu I saw you also posted on the github issue. Sorry, I think this is the current status, but there is some (slow) work on it. But eventually RN will have to support 64bit, sometime soon I think. – Arnold Schrijver Aug 11 '17 at 07:55
  • 1
    Is it supposed to work properly now with react-native 60.5? I still get the same error with 60.5 even though react native added support for 64 bit in 59.1. – Vivek Maskara Sep 11 '19 at 04:44
  • 2
    How is this a solution? – Andrew Koster Oct 22 '19 at 20:57
5

To me what worked was to clean project build and build it again. enter image description here

4

Solution 1:

follow these steps:

  1. uninstall the app from the device
  2. close Metro Bundler
  3. run ./gradlew clean on android directory
  4. run react-native run-android

hope to help you.

Solution 2:

you can use the old version of soloader by adding configurations.all into your build.gradle

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

like this

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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
}

reference https://stackoverflow.com/a/61695629/8079868

Muhammad Numan
  • 23,222
  • 6
  • 63
  • 80
2

I solved this issue, update fresco library that is support for app bundle is 2.0.0 below this will not support,

Update: For me the issue got solved after updating fresco to 2.0.0, because 1.11.0 apparently didn't have support for Android App Bundles. I don't know if you all had the same problem, though.

just do this :

implementation 'com.facebook.fresco:fresco:2.0.0'
Najaf Ali
  • 1,433
  • 16
  • 26
1

I had the same issue when running on Android 30. Following addition to the android/build.gradle file worked for me:

configurations.all {
        resolutionStrategy {
           // use 0.9.0 to fix crash on Android 11
            force "com.facebook.soloader:soloader:0.9.0"
  }
}

Credits

Mahendra Liya
  • 12,912
  • 14
  • 88
  • 114
1

This worked for me,

cd android
./gradlew clean
pravchuk
  • 903
  • 10
  • 14
0

It might be lib\x86_64\libreactnativejni.so not found due to missing strip tool for ABI 'X86_64' Try the following steps.

  1. Uninstall the apk
  2. Clean the android folder

    • Navigate to android folder cd android.

    • Clean the directory using gradle

    • For Windows, gradlew clean

    • For Linux, ./graldew clean
  3. Now you can try react-native run-android --no-jetifier

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

Step 1: Goto Android Studio -> Build -> clean project. Step 2: delete the project in your device. Step 3: run react-native start. Step 4: run npx react-native run-android.

  • It's working for me, no need of any gradle related changes.
-3

if you are fresco libray then make sure use latest version and set the properties as false :

shrinkResources false
minifyEnabled false

Inside build.gradle file.

olibiaz
  • 2,551
  • 4
  • 29
  • 31