23

I am working with react native and every time I build a new project it seems to work on my device , but whenever I try to restart it It is giving me 1 or more errors

I have tried looking for solutions on github but none of them are clear I will post the entire error message here.

react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 855 file(s) to forward-jetify. Using 4 workers... info Starting JS server... info Installing the app... Starting a Gradle Daemon (subsequent builds will be faster)

Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings 24 actionable tasks: 2 executed, 22 up-to-date

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.

    Could not read path 'C:\REACT_NATIVE\AwesomeProject2\android\app\build\intermediates\transforms\mergeJniLibs\debug\0\lib\arm64-v8a'.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 57s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.

    Could not read path 'C:\REACT_NATIVE\AwesomeProject2\android\app\build\intermediates\transforms\mergeJniLibs\debug\0\lib\arm64-v8a'.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 57s

at checkExecSyncError (child_process.js:623:11)
at execFileSync (child_process.js:641:15)
at runOnAllDevices (C:\REACT_NATIVE\AwesomeProject2\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:75:39)
at buildAndRun (C:\REACT_NATIVE\AwesomeProject2\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:169:41)
at C:\REACT_NATIVE\AwesomeProject2\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:135:12
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at async Command.handleAction (C:\REACT_NATIVE\AwesomeProject2\node_modules\react-native\node_modules\@react-native-community\cli\build\cliEntry.js:160:7)
Kaustubh Jha
  • 881
  • 1
  • 6
  • 7

8 Answers8

64

Running the cleaning task solved the problem for me. In your project's android dir, run gradle wrapper with 'clean'

cd android && ./gradlew clean 

Then you can go back to project dir and try running again.

cd .. && react-native run-android
semihcosu
  • 346
  • 2
  • 12
Kaustubh Jha
  • 881
  • 1
  • 6
  • 7
14

go to android/app/build.gradle add the following under android

android {
    ...
+   packagingOptions {
+       pickFirst '**/libjsc.so'
+       pickFirst 'lib/x86/libc++_shared.so'
+       pickFirst 'lib/x86_64/libjsc.so'
+       pickFirst 'lib/arm64-v8a/libjsc.so'
+       pickFirst 'lib/arm64-v8a/libc++_shared.so'
+       pickFirst 'lib/x86_64/libc++_shared.so'
+       pickFirst 'lib/armeabi-v7a/libc++_shared.so'  
+   }
}

Running the cleaning task solved the problem for me. In your project's android dir, run gradle wrapper with 'clean'

cd android && ./gradlew clean

Then you can go back to project dir and try running again.

cd .. && react-native run-android

Plutian
  • 2,276
  • 3
  • 14
  • 23
Pero Albert
  • 151
  • 1
  • 2
  • This should be the accepted answer because after adding these code I can run the app without cleaning the gradlew. – Eaten Taik Sep 24 '20 at 01:04
2

Clean project working for me

A react-native Project is about one XCode Project and one Android Project. (pure js code no need to do clean)

So what are you need would be

Clean XCode Project with

$ cd ios
$ xcodebuild clean
$ cd .. && react-native run-ios

And then clean Android Project with

$ cd android
$ ./gradlew clean
$ cd .. && react-native run-android

You can simply write a batch file for it.

Parveen Chauhan
  • 1,396
  • 12
  • 25
2

in my case in react-native app this error was beacause of rn-fetch-blob v0.12.0, and it makes release apk crash too
i do this:

npm uninstall rn-fetch-blob
npm i rn-fetch-blob@0.11.2
cd android && gradlew clean
cd..
react-native run-android

hope this help somebody <3

amirhosein
  • 844
  • 9
  • 24
1

Go to android/app/build.gradle and add the following thing under android:

android {
  packagingOptions {
      pickFirst '**/libjsc.so'

  }
}

Then run it again. If your using react native i suggest you to close npm console and run it again.

Deepak N
  • 1,408
  • 3
  • 15
  • 37
1

AAR libraries were not linking to the Main application from Bridge Project.

Solution:

implementation files(‘libs/sdk-5.0.0.aar’)

Instead of

implementation(name:'sdk-5.0.0', ext:'aar')

I faced another issue related to AAR file import into the android project. https://stackoverflow.com/a/58602329/3197778

FAHID
  • 3,245
  • 3
  • 18
  • 15
1

go to android/app/build.grad

    ...
+   packagingOptions {
+       pickFirst '**/libjsc.so'
+       pickFirst 'lib/x86/libc++_shared.so'
+       pickFirst 'lib/x86_64/libjsc.so'
+       pickFirst 'lib/arm64-v8a/libjsc.so'
+       pickFirst 'lib/arm64-v8a/libc++_shared.so'
+       pickFirst 'lib/x86_64/libc++_shared.so'
+       pickFirst 'lib/armeabi-v7a/libc++_shared.so'  
+   }
}
Nick Vu
  • 14,512
  • 4
  • 21
  • 31
Pero Albert
  • 151
  • 1
  • 2
0

Go to android/app/build.gradle and add the following thing under android:

packagingOptions {
   pickFirst 'lib/x86/libswscale.so'
   pickFirst 'lib/x86/libavcodec.so'
   pickFirst 'lib/x86/libavformat.so'
   pickFirst 'lib/x86/libavutil.so'
   pickFirst 'lib/x86/libfbjni.so'
   pickFirst 'lib/x86/libc++_shared.so'
   pickFirst 'lib/x86_64/libavutil.so'
   pickFirst 'lib/x86_64/libavcodec.so'
   pickFirst 'lib/x86_64/libswscale.so'
   pickFirst 'lib/x86_64/libavformat.so'
   pickFirst 'lib/x86_64/libfbjni.so'
   pickFirst 'lib/x86_64/libc++_shared.so'
   pickFirst 'lib/arm64-v8a/libavcodec.so'
   pickFirst 'lib/arm64-v8a/libavformat.so'
   pickFirst 'lib/arm64-v8a/libavutil.so'
   pickFirst 'lib/arm64-v8a/libswscale.so'
   pickFirst 'lib/arm64-v8a/libc++_shared.so'
   pickFirst 'lib/arm64-v8a/libfbjni.so'
   pickFirst 'lib/armeabi-v7a/libavutil.so'
   pickFirst 'lib/armeabi-v7a/libavformat.so'
   pickFirst 'lib/armeabi-v7a/libavcodec.so'
   pickFirst 'lib/armeabi-v7a/libswscale.so'
   pickFirst 'lib/armeabi-v7a/libfbjni.so'
   pickFirst 'lib/armeabi-v7a/libc++_shared.so'

}