holepunchto / bare-crypto

Cryptographic primitives for JavaScript
Apache License 2.0
6 stars 0 forks source link

bare-crypto not building for Android. #3

Closed supersuryaansh closed 3 weeks ago

supersuryaansh commented 3 weeks ago

I am using the pear-expo-hello-world example.

"bare-dev": "^0.11.3"

Trying to build for Android with command npx expo run:android --no-build-cache results in build failure and the following errors:

` › Building app... Configuration on demand is an incubating feature.

Configure project :expo

Using expo modules

Task :hello-bare:buildCMakeDebug[arm64-v8a] FAILED C/C++: ninja: Entering directory `/Users/supersu/Developer/holesail-go/modules/hello-bare/android/.cxx/Debug/2u6h4p5p/arm64-v8a' C/C++: : && /Users/supersu/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android24 --sysroot=/Users/supersu/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=c++20 -fno-limit-debug-info -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libhello_bare_jsi.so -o /Users/supersu/Developer/holesail-go/modules/hello-bare/android/build/intermediates/cxx/Debug/2u6h4p5p/obj/arm64-v8a/libhello_bare_jsi.so CMakeFiles/hello_bare_jsi.dir/hello-bare.cc.o /Users/supersu/.gradle/caches/transforms-3/20e14a3a1faed9ce3da9af0343545221/transformed/jetified-fbjni-0.5.1/prefab/modules/fbjni/libs/android.arm64-v8a/libfbjni.so /Users/supersu/.gradle/caches/transforms-3/88e91636c34a355bbd9286e87088f8a5/transformed/jetified-react-android-0.73.4-debug/prefab/modules/jsi/libs/android.arm64-v8a/libjsi.so /Users/supersu/.gradle/caches/transforms-3/88e91636c34a355bbd9286e87088f8a5/transformed/jetified-react-android-0.73.4-debug/prefab/modules/turbomodulejsijni/libs/android.arm64-v8a/libturbomodulejsijni.so /Users/supersu/.gradle/caches/transforms-3/88e91636c34a355bbd9286e87088f8a5/transformed/jetified-react-android-0.73.4-debug/prefab/modules/react_nativemodule_core/libs/android.arm64-v8a/libreact_nativemodule_core.so /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libv8.a /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/misc/libc++.a /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libjs.a -Wl,--whole-archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libbare.a -Wl,--no-whole-archive -Wl,--whole-archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a -Wl,--no-whole-archive -landroid /Users/supersu/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/24/liblog.so -latomic -lm && : C/C++: ld: error: undefined symbol: EVP_MD_CTX_init C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_md5 C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_sha256 C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_sha512 C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_sha1 C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_DigestInit C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_MD_CTX_cleanup C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_init) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_DigestUpdate C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_update) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_MD_CTX_size C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_final) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: EVP_DigestFinal C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_hash_final) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: ld: error: undefined symbol: RAND_bytes C/C++: >>> referenced by binding.c C/C++: >>> binding.c.o:(bare_crypto_random_fill) in archive /Users/supersu/Developer/holesail-go/bare-libs/android/arm64-v8a/libhello_bare.a C/C++: clang++: error: linker command failed with exit code 1 (use -v to see invocation) C/C++: ninja: build stopped: subcommand failed.

FAILURE: Build failed with an exception.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 5s 271 actionable tasks: 11 executed, 260 up-to-date Error: /Users/supersu/Developer/holesail-go/android/gradlew exited with non-zero code: 1 Error: /Users/supersu/Developer/holesail-go/android/gradlew exited with non-zero code: 1 at ChildProcess.completionListener (/Users/supersu/Developer/holesail-go/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23) at Object.onceWrapper (node:events:634:26) at ChildProcess.emit (node:events:519:28) at maybeClose (node:internal/child_process:1105:16) at ChildProcess._handle.onexit (node:internal/child_process:305:5) ... at Object.spawnAsync [as default] (/Users/supersu/Developer/holesail-go/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21) at spawnGradleAsync (/Users/supersu/Developer/holesail-go/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46) at Object.assembleAsync (/Users/supersu/Developer/holesail-go/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18) at runAndroidAsync (/Users/supersu/Developer/holesail-go/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:36:24) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) supersu@Suryaanshs-Laptop holesail-go % `

This does not happen on iOS but importing the module in iOS results in a white screen of death and nothing shows up in the app:

This is how I am trying to use it: const {createHash} = require('bare-crypto');

kasperisager commented 3 weeks ago

bare-crypto builds just fine on Android, the issue is how it's integrated into Expo. ~Moving this issue.~ I don't seem to be able to transfer the issue, could you open a new one in https://github.com/holepunchto/pear-expo-hello-world? Thanks!

supersuryaansh commented 3 weeks ago

@kasperisager Can you tell me what do you mean by "how it's integrated into Expo" and what do I need to do to resolve this?

kasperisager commented 3 weeks ago

There's a bunch of outstanding issues in the Expo example repo and some PRs that fixes some of it. I'd start by looking into whether one of those fixes might do the trick.

supersuryaansh commented 3 weeks ago

@kasperisager I have compiled most of the PRs and fixed the expo-example in https://github.com/supersuryaansh/pear-expo-android-ios-app/.

Issues were related to links files and file paths, but this issue persists. It does not happen with any other module I have tried but this

kasperisager commented 3 weeks ago

As mentioned, the issue is linking as the BoringSSL symbols aren't included for some reason. It works fine in https://github.com/holepunchto/bare-android, I just ran this without issue:

console.log(require('bare-crypto').createHash('md5').update('Hello world!').digest('base64'))
supersuryaansh commented 3 weeks ago

@kasperisager Is there anything I can do to fix BoringSSL symbols?

kasperisager commented 3 weeks ago

Most likely! The first step would be figuring out why the BoringSSL libraries aren't included in the amalgamated archive. Try logging the dependency variable here so see if ssl and crypto show up: https://github.com/holepunchto/cmake-bare/blob/91d6d176345dd9324794de0c61046c782ea71fed/bare.cmake#L414