Tadas Tadas - 5 months ago 728
Android Question

How to properly use NDK-Build in Android Studio 2.2 Preview 1

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 enter image description here

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

Answer

Android Studio 2.3 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.

Comments