numandev1 / react-native-keys

πŸ” Protected .ENVs variables in React Native πŸš€βœ¨
MIT License
314 stars 27 forks source link

Fails to build on ANdroid #18

Closed justintoth closed 1 year ago

justintoth commented 1 year ago

Current behavior

When trying to build on Android, it's giving the error:

Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction > 2 files found with path 'lib/arm64-v8a/libcrypto.so' from inputs: - /Users/justintoth/Dev/m365-mobile-app/node_modules/react-native-keys/android/build/intermediates/library_jni/debug/jni/arm64-v8a/libcrypto.so - /Users/justintoth/.gradle/caches/transforms-3/21df3bd3ae107d2ee802eb869f41fec9/transformed/jetified-flipper-0.182.0/jni/arm64-v8a/libcrypto.so If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/r/tools/jniLibs-vs-imported-targets 

Expected behavior

It should build properly.

Platform

React Native Version

0.72.1

github-actions[bot] commented 1 year ago

πŸ‘‹ @justintoth Thanks for opening your issue here! If you find this package useful hit the star🌟!

numandev1 commented 1 year ago

@justintoth can you try this code in build.gralde and check

 android{
    ........

    packagingOptions {
        pickFirst 'lib/arm64-v8a/libcrypto.so'
    }
  }
justintoth commented 1 year ago

@numandev1 Thanks for the quick reply! It didn't work, it still throws the same error if I add that in my android/app/build.gradle file. I also looked in my android/build.gradle file but it doesn't have an android section, so I assume the android/app file is the correct one.

Execution failed for task ':app:mergeDebugNativeLibs'.

A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction > 2 files found with path 'lib/armeabi-v7a/libcrypto.so' from inputs: - /Users/justintoth/Dev/m365-mobile-app/node_modules/react-native-keys/android/build/intermediates/library_jni/debug/jni/armeabi-v7a/libcrypto.so - /Users/justintoth/.gradle/caches/transforms-3/21df3bd3ae107d2ee802eb869f41fec9/transformed/jetified-flipper-0.182.0/jni/armeabi-v7a/libcrypto.so If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/r/tools/jniLibs-vs-imported-targets

What does "fix" it is if I add libcrypto.so to the excludes in the android/build.gradle file in the react-native-keys node_modules folder.

packagingOptions {
    excludes = ['**/libc++_shared.so',
                '**/libfbjni.so',
                '**/libreactnativejni.so',
                '**/libjsi.so',
                '**/libreact_nativemodule_core.so',
                '**/libturbomodulejsijni.so',
                '**/libcrypto.so'
    ]
  }

I can permanently apply this by using patch-package, but it doesn't seem like a great solution.

numandev1 commented 1 year ago

@justintoth Actually, somehow two packages are compiling the same file, good approach is to use pickFirst, you can connect with me on LinkedIn https://www.linkedin.com/in/numandev, we can see it on zoom session

efstathiosntonas commented 1 year ago

Hey folks, did you managed to solve this? Thanks

numandev1 commented 1 year ago

@efstathiosntonas can you try this code in build.gralde and check

 android{
    ........

    packagingOptions {
        pickFirst '**/libcrypto.so'
    }
  }
efstathiosntonas commented 1 year ago

@numandev1 that didn't work :/

stacktrace:

com.facebook.react.common.JavascriptException: Error: Exception in HostObject::get for prop 'Keys': java.lang.UnsatisfiedLinkError: dlopen failed: library "libcrypto.so" not found: needed by /data/app/~~kDSZuwRkmz7M6dR5GmEBnw==/com.XXXX-vYdc4DF9x4eWt9v_mxqDjw==/lib/arm64/libreact-native-keys.so in namespace clns-7, js engine: hermes, stack:
    packagingOptions {
        pickFirst "**/armeabi-v7a/libc++_shared.so"
        pickFirst "**/x86/libc++_shared.so"
        pickFirst "**/arm64-v8a/libc++_shared.so"
        pickFirst "**/x86_64/libc++_shared.so"
        pickFirst "**/x86/libjsc.so"
        pickFirst "**/armeabi-v7a/libjsc.so"
        pickFirst "**/libcrypto.so"
    }
numandev1 commented 1 year ago

@efstathiosntonas can you comment this line from node_modules and check?

https://github.com/numandev1/react-native-keys/blob/cfef434b0433c9c25ffb2e61a0702fab9615178e/android/build.gradle#L160

efstathiosntonas commented 1 year ago

@numandev1 shall I keep the pickFirst "**/libcrypto.so" on app/build.gradle?

numandev1 commented 1 year ago

@efstathiosntonas you can remove pickFirst "**/libcrypto.so" and comment that line from node_modules and check

efstathiosntonas commented 1 year ago

@numandev1 I still get the issue :/

ps. on release

numandev1 commented 1 year ago

@efstathiosntonas can you connect with me on LinkedIn https://www.linkedin.com/in/numandev ?, we can see it on Zoom session, it is night-time in Pakistan, and going to sleep now,

the issue is some code is excluding libcrypto.so file in our apk, which is required in for using this package

efstathiosntonas commented 1 year ago

sure, let's talk tomorrow!

efstathiosntonas commented 6 months ago

@numandev1 Hi, I upgraded to rn@0.74 and this error is back:

 Error: Exception in HostObject::get for prop 'Keys': java.lang.UnsatisfiedLinkError: dlopen failed: library "libcrypto.so" not found: needed by /data/app/~~3zZNXhfiC-LaMn2O-GcCHQ==/com.XXXXX-MMetn9UteJY31KDgHH2bbw==/base.apk!/lib/arm64-v8a/libreact-native-keys.so in namespace clns-8, js engine: hermes

any ideas?

efstathiosntonas commented 6 months ago

@numandev1 I have a feeling that since Flipper was removed entirely on react-native@0.74 it fails to find the libcrypto.so, libcrypto was used by Flipper so my guess is that libcrypto is never installed anymore somewhere during the build process.