cargo-ndk-android-gradle
cargo-ndk-android-gradle copied to clipboard
Including libc++_shared.so
One of my rust dependencies links to the shared version of the C++ STL libc++. (Specifically, I'm trying to use oboe-rs with the shared-stdcxx
feature.)
After building this all with the cargo ndk gradle plugin, I'm getting link errors at runtime: java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
From reading here (also a later section in that page) and here, it sounds like if you link to libc++_shared.so
you need to include it in your app. Moreover it says that if you use gradle, this should be done for you.
Since this is a gradle plugin, does that mean that it's this plugin's job to make that happen? I don't know if this logic is sound - I am completely out of my depth here just trying to get something working. But I thought I'd try raising an issue in case it is the job of this plugin. Also, if anyone has any insight as to how to go this manually / some other way, I'd love to hear it.
From googling, people seem convinced that all you need to get gradle to include libc++_shared.so
in your APK is to add
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
}
}
to android::default_config
in your module's gradle.build
. However, for me that does nothing, since I'm not using cmake.
So my extremely hacky workaround is to just start using cmake. I just get it to build an empty c++ source file as a library, and then that bit above actually works (if you analyze the apk you can see libc++_shared.so
inside lib/<abi>
). I don't recommend this as a good solution, obviously. I can't shake the feeling that since I'm using this gradle plugin instead of cmake, it should be this gradle plugin that puts libc++_shared.so
in place.
If anyone reading this actually wants to do this hack, then here's a gist: https://gist.github.com/chriscoomber/015222b17b2af9ebc84a0438e192a9af
Hi, thanks for the issue report. Linking with C++ is usually messy. Do you have a small project where the issue is reproduced, so I could play around and see how this plugin can implement this feature?