Execution failed for task ':app:mergeDebugNativeLibs'. in react native
Asked Answered
C

10

40

I installed react-native-pdf and now when I run "npx react-native run-android", it fails with the following:

* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'lib/x86/libc++_shared.so'

Can anyone help me use the package react-native-pdf?

ive

Cimah answered 25/9, 2020 at 18:19 Comment(0)
A
66

I had the same issue and i resolved it by adding the following to android/app/build.gradle

android {

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

/** rest of your code here **/

}

Alderson answered 29/9, 2020 at 9:6 Comment(3)
does anyone know why do we need to do this? i really dont like gradle tool, there is no explanation...Jolt
Gives the impression that including the react native pdf reader library somehow introduces other versions of these files and you're telling the compiler which ones to look at or something?Mra
This feels like a hack...Cylinder
G
13

add this to your app/build.gradle

android {
   // yout existing code
   packagingOptions {
        pickFirst '**/libc++_shared.so'
        pickFirst '**/libfbjni.so'
    }
}
Gnome answered 6/11, 2022 at 3:55 Comment(0)
T
4

Open the project in Android Studio android and clean the project Build -> Clean Project

Trinitrophenol answered 25/3, 2021 at 16:51 Comment(1)
Thanks.. it was just a stale environment. Running flutter -clean worked.Rhody
C
2

Add this code to "/android/app/build.gradle"

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

So run this on the terminal

$ cd android/
$ ./gradlew cleanBuildCache
$ cd ..
$ sudo npx react-native run-android
Cantilena answered 18/10, 2021 at 17:57 Comment(0)
H
0

For us, it was caused by react-native-pdf.

So either, eject the project and update build.gradle same as other answers say or, get rid of it if not used or you may replace it with rn-pdf-reader-js

Himself answered 28/6, 2022 at 13:58 Comment(3)
Which solution did you go with? Had you updated your Gradle file if yes? what changes were needed exactly?Esthonia
We used rn-pdf-reader-js. It's much more betterHimself
rn-pdf-reader-js is only available for expo projects; if you're running a CRA build you can't use it it seemsCylinder
K
0

For me its gradle cache issue, I fixed it by running running the following command in the project's root directory:

cd android

and after

./gradlew clean
Knighterrant answered 6/8, 2023 at 19:48 Comment(0)
V
0

Add this code to "/android/app/build.gradle"

android {
  packagingOptions {
      pickFirst 'lib/x86/libc++_shared.so'
      pickFirst 'lib/x86_64/libc++_shared.so'
      pickFirst 'lib/armeabi-v7a/libc++_shared.so'
      pickFirst 'lib/arm64-v8a/libc++_shared.so'
  }
}
Vermilion answered 24/4 at 20:29 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Mannes
G
0

I had the same issue in flutter and "pickFirst" worked fine but its important to have that in the main app build gradle not in the plugin one.

Gillenwater answered 1/7 at 19:54 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewHusted
L
-1

i changed minSdkVersion to 21 in "android/app/build.gradle".

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.custom_epub_view"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
League answered 9/1, 2021 at 8:45 Comment(0)
H
-1

android build.gradle file under allprojects add following

allprojects {
   configurations.all {
   resolutionStrategy {
   force 'com.facebook.react:react-native:0.65.2' //select Version you used
   }
}

https://github.com/facebook/react-native/issues/35215#issuecomment-1304878829

Heliopolis answered 24/11, 2022 at 15:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.