I use APP_STL := c++_shared
to build my Android application, and I would like to include a custom version of this library, and link against it and package it inside APK. But, regardless of what I do, Android Studio includes the version of libc++_shared.so
from NDK. Among the logs it has
[arm64-v8a] "Prebuilt ": "libc++_shared.so <= <NDK>/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/"
I tried putting my version of the library in jniLibs
, but it complains about duplicated libraries. When I add into my build.gradle
file packagingOptions
, it still prefers to package the NDK version into APK
packagingOptions {
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
I tried to link against my version of the library inside Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := my_c++_shared
LOCAL_SRC_FILES := $(MY_LIB_DIR)/libc++_shared.so
include $(PREBUILT_SHARED_LIBRARY)
It links against, it but then again packages the NDK version, and because of that the application crashes.
So how do I proceed to ignore NDK version? Setting APP_STL := none
leads to no C++ standard library at all, even headers
This is a missing feature in AGP. As far as I know there is no workaround. Subscribe/upvote https://issuetracker.google.com/214395989.
I would like to include a custom version of this library
FWIW, you're well off into the weeds with this, and this could cause some painful compatibility issues with any third-party code (including androidx) that you need to use now or in the future. Not saying "don't do that", just a heads up.