wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.6k stars 550 forks source link

android getting error at run time More than one file was found with OS independent path 'lib/x86/libjsc.so' #432

Open anuj-njoshi opened 4 years ago

anuj-njoshi commented 4 years ago

More than one file was found with OS independent path 'lib/x86/libjsc.so'

aca-hakan-pinar commented 4 years ago

Me too! Versions:"react": "16.9.0", "react-native": "0.61.5",

jayeshgurudayalani commented 4 years ago

https://stackoverflow.com/a/48231124 May this answer helps

aca-hakan-pinar commented 4 years ago

I have tried this solution, but it didn't work.

jayeshgurudayalani commented 4 years ago

@aca-hakan-pinar I had faced same and applied given solution and it is working . can you post error stack trace and gradle file where you applied solution

ferhatsal commented 4 years ago

I've faced the same and found the solution ( at least it woked for me : )

add android/app/build.gradle file into andorid : {.....} section this :

    packagingOptions {
        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'
    }

then use "gradlew clean" ( without cleaning it causes a different error )

kyktommy commented 4 years ago

Here is my fix, in android/app/build.gradle

android {
  packagingOptions {
    pickFirst '**/libjsc.so'
  }
}
WilcoBreedt commented 3 years ago

I've faced the same and found the solution ( at least it woked for me : )

add android/app/build.gradle file into andorid : {.....} section this :

    packagingOptions {
        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'
    }

then use "gradlew clean" ( without cleaning it causes a different error )

So I used almost the same packagingOptions, can confirm that this is working

   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'
    }
aslu2183 commented 3 years ago

@WilcoBreedt , I used this on my app/build.gradle file. Now Build Succeed. But when app open it will crash. My React-native Version is 0.61.5

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' }

WilcoBreedt commented 3 years ago

@aslu2183 I also had a new error the first time, have you tried running gradlew clean? This will get rid of previous build artifacts that can cause errors

aslu2183 commented 3 years ago

@WilcoBreedt , Yes i ran gradlew clean. But same problem happens. But in React native Version 0.63.4 its working fine when adding Packaging Options and App Not Crashing. Problem in Version 0.61.5

WilcoBreedt commented 3 years ago

@aslu2183 Maybe attempt to downgrade your version of react-native-pdf. I am not sure if that could fix it for you.

aslu2183 commented 3 years ago

@WilcoBreedt Ok,thank you for your kind information

Ilphrin commented 3 years ago

Hello! Having the same issue here, though not with libjsc.so, @ferhatsal's solution seems to work but is there any plans to fix this issue ?

* 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/arm64-v8a/libc++_shared.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake
gustavohcastro commented 2 years ago

@WilcoBreedt , I used this on my app/build.gradle file. Now Build Succeed. But when app open it will crash. My React-native Version is 0.61.5

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' }

this works for me, thanks!!!

kmlrmdhn commented 2 years ago

Hello! Having the same issue here, though not with libjsc.so, @ferhatsal's solution seems to work but is there any plans to fix this issue ?

* 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/arm64-v8a/libc++_shared.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

pickFrist 'lib/arm64-v8a/libc++_shared.so'

vaish8529 commented 1 year ago

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/armeabi-v7a/libfbjni.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

In my app/build.gradle

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

but same issue

mklb commented 1 year ago

Works

packagingOptions {
    pickFirst '**/libc++_shared.so'
    pickFirst '**/libfbjni.so'
}
codal-mpawar commented 1 year ago

Now Build Succeed. But when the app opens it will crash.

Works

packagingOptions {
    pickFirst '**/libc++_shared.so'
    pickFirst '**/libfbjni.so'
}
codal-mpawar commented 1 year ago

@mklb @aslu2183

rutul-mehta commented 1 year ago

@codal-mpawar Did you find any solution? I am facing the same issue

h-assefi commented 1 year ago

Same problem here. it builds but the app crashes

ALI-SAMPSON commented 1 year ago

Same problem here

codal-mpawar commented 1 year ago

Please try with this it's working fine in my device.


packagingOptions {
        pickFirst "**/libc++_shared.so"
        resources.excludes.add("META-INF/*")
    }
YadongChen commented 1 year ago

The above scheme using packagingOptions - pickFirst is undoubtedly useful (上述使用packagingOptions - pickFirst的方案毫无疑问是有用的)

But I would like to recommend another similar solution to solve multiple "libc++_shared.so" files, which may be more controllable than the current "android-installation" solution (但是我想推荐另一个类似的,解决多个"libc++_shared.so"文件的方案,可能比现在的"android-installation"中方案更可控)

In my project:react-native 0.68.x at the same time:

  1. react-native-pdf
  2. react-native-vlc-media-player

Both the above two third-party libraries and react-native itself have "libc++_shared.so" files, and there may even be three competitions at the same time (上述两个第三方库和react-native本身都存在"libc++_shared.so"文件,甚至会同时有3个竞争)

In react-native-vlc-media-player的README, a gradle-task is introduced to control which "libc++_shared.so" file should be kept (react-native-vlc-media-player的README中,介绍了一个gradle-task,目的是可以控制应该保留哪个"libc++_shared.so"文件)

As mentioned in the introduction of README, if the "libc++_shared.so" file of react-native-vlc-media-player is not used, the app may crash (如README的介绍所说,如果不使用react-native-vlc-media-player的"libc++_shared.so"文件,app会存在crash可能)

In other cases, it will also become: "couldn't find DSO to load: libjscexecutor.so" (其他情况下,也会变成:"couldn't find DSO to load: libjscexecutor.so")

When using pickFirst to solve, it seems that there is no certain "certainty" (而使用pickFirst来解决时,似乎并没有一定的"确定性")

And this gradle-task can also be extended to be used by other so files (而且这个gradle-task也可以扩展,以为其他so文件使用)

android/app/build.gradle


// 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'
// }

...

tasks.whenTaskAdded {
    Task mapTask -> {
        // when task is 'mergeLocalDebugNativeLibs' or 'mergeLocalReleaseNativeLibs'
        if (mapTask.name.contains("merge") && mapTask.name.contains("NativeLibs")) {
            tasks.named(mapTask.name) {
                MergeNativeLibsTask needUpdateMergeNativeLibsTask -> doFirst {
                    needUpdateMergeNativeLibsTask.externalLibNativeLibs
                        .getFiles()
                        .stream()
                        // for React Native 0.71, the file value now contains "jetified-react-android" instead of "jetified-react-native"
                        //  react-native-pdf - jetified-PdfiumAndroid
                        .filter(needMarkExternalLibNativeLibsDirectory ->
                                needMarkExternalLibNativeLibsDirectory.toString().contains("jetified-react-native")
                                        || needMarkExternalLibNativeLibsDirectory.toString().contains("jetified-PdfiumAndroid")
                        )
                        .map(needMarkExternalLibNativeLibsDirectory -> needMarkExternalLibNativeLibsDirectory.toPath())
                        .forEach(needRemoveNotNeedSoFileDirectoryPath -> {
                            java.nio.file.Files.walk(needRemoveNotNeedSoFileDirectoryPath).forEach(notNeedSoFilePath -> {
                                if (notNeedSoFilePath.toString().contains("libc++_shared.so")) {
                                    java.nio.file.Files.delete(notNeedSoFilePath);
                                }
                            })
                        });
                }
            }
        }
    }
}