Android Studio 2.2 Preview 1 has a new external ndk build feature, but from app/build.gradle
snippet shown in official blog post it's not clear at all how to set additional ndk build parameters which Application.mk
file usually contains
I'm able to set Android.mk
ndk build file via externalNativeBuild
, but how could I set the required Application.mk
variables?
My Application.mk
contains:
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-16
APP_ABI := armeabi
APP_STL := c++_static
APP_CPPFLAGS += -std=c++11
Android Studio 2.2 Preview 3 with updated gradle plugin added support for additional arguments. You can set Application.mk and additional configuration like this:
defaultConfig {
ndkBuild {
arguments "NDK_APPLICATION_MK:=Application.mk"
cFlags "-DTEST_C_FLAG1" "-DTEST_C_FLAG2"
cppFlags "-DTEST_CPP_FLAG2" "-DTEST_CPP_FLAG2"
abiFilters "armeabi-v7a", "armeabi"
}
}
If possible I would recommend migrating to CMake build system, because of better C++ code editor and debugging integration in Android Studio. You will find more info on gradle plugin configuration here: https://sites.google.com/a/android.com/tools/tech-docs/external-c-builds.
Edit:
From Android Studio 2.2 Preview 5 you must wrap cmake
and ndkBuild
groups under externalNativeBuild
group:
defaultConfig {
externalNativeBuild {
ndkBuild {
targets "target1", "target2"
arguments "NDK_APPLICATION_MK:=Application.mk"
cFlags "-DTEST_C_FLAG1", "-DTEST_C_FLAG2"
cppFlags "-DTEST_CPP_FLAG2", "-DTEST_CPP_FLAG2"
abiFilters "armeabi-v7a", "armeabi"
}
}
}
Edit 2: It seems that wrapping ndkBuild
under externalNativeBuild
group does not work because of a bug in build tools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With