Error linking libjuce_jni from gradlew


#1

I’m trying to build my app into an APK using gradlew assemble, and getting the following error:

linking libjuce_jni.so failed.
/Users/adamelemental/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:840: error: undefined reference to '__atomic_load_1'
/Users/adamelemental/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:834: error: undefined reference to '__atomic_store_1'
/Users/adamelemental/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:840: error: undefined reference to '__atomic_load_4'
/Users/adamelemental/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:834: error: undefined reference to '__atomic_store_4'
/Users/adamelemental/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:834: error: undefined reference to '__atomic_store_1'
/Users/adamelemental/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:840: error: undefined reference to '__atomic_load_4'
/Volumes/Android/buildbot/src/android/ndk-r12-release/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:922: error: undefined reference to '__atomic_fetch_add_4'
/Volumes/Android/buildbot/src/android/ndk-r12-release/ndk/sources/cxx-stl/llvm-libc++abi/libcxxabi/src/cxa_handlers.cpp:112: error: undefined reference to '__atomic_exchange_4'
/Volumes/Android/buildbot/src/android/ndk-r12-release/ndk/sources/cxx-stl/llvm-libc++abi/libcxxabi/src/cxa_default_handlers.cpp:106: error: undefined reference to '__atomic_exchange_4'
/Volumes/Android/buildbot/src/android/ndk-r12-release/ndk/sources/cxx-stl/llvm-libc++abi/libcxxabi/src/cxa_default_handlers.cpp:117: error: undefined reference to '__atomic_exchange_4'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Its the same whether I do assembleDebug or assembleRelease. Any ideas? Is there a compiler flag missing?

BTW it works fine in AndroidStudio. I have an Android-related build issue with missing asset links which I’m trying to solve using gradlew.


#2

Ahh yes I remember this bug. I think you can’t use the clang C++ library with arm64 at the moment (bug in the ndk). I think the gcc toolchain will work though. Make sure that you have

APP_STL := gnustl_static

in the Application.mk Makefile.


#3

Thanks, I made the following changes to build.gradle

android.ndk {
        moduleName = "juce_jni"
        //toolchain = "clang"
        toolchain = "gcc"
        //stl = "c++_static"
        stl = "gnustl_static"

And just got a successful build :slight_smile: