Reputation: 61380
Android Studio, a project with an NDK library, using ndkBuild with Android.mk. My build uses a static library dependency, and the static library exists as a debug and as a release flavor, in separate directories. The makefile goes:
#Ref to libfoo
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := $(FOOPROJECT)\foo\build\intermediates\ndkBuild\debug\obj\local\$(TARGET_ARCH_ABI)\libfoo.a
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_SRC_FILES
has the debug
flavor hard-coded as a part of the path. Not good. I'd like to use either "debug" or "release" there, depending on the current build type.
Is the current build type available in the makefile as a variable? If not, is is possible to pass it to ndk-build via the gradle file?
Upvotes: 2
Views: 2720
Reputation: 209
NDK_DEBUG
is the var what you need, 1
is debug, 0
is release.
ifeq ($(NDK_DEBUG), 1)
BUILD_TYPE := debug
else
BUILD_TYPE := release
endif
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := $(FOOPROJECT)\foo\build\intermediates\ndkBuild\$(BUILD_TYPE)\obj\local\$(TARGET_ARCH_ABI)\libfoo.a
include $(PREBUILT_STATIC_LIBRARY)
Other useful vars:
APP_BUILD_SCRIPT
: Android.mk
pathNDK_APPLICATION_MK
: Application.mk
pathAPP_ABI
: Same like TARGET_ARCH_ABI
NDK_OUT
: the build obj pathNDK_LIBS_OUT
: build lib pathAPP_PLATFORM
: Target os and api version,like android-21
You can check this file :
ProjectPath/ModuleName/build/.cxx/$(BUILD_TYPE)/xxxx/$(TARGET_ARCH_ABI)/android_gradle_build_command_ModuleName_$(TARGET_ARCH_ABI).txt
too see more info.
And here is a Android NDK demo, you can check the lib_module_provider
and lib_module_beneficiary
to see how to use pre-built
library by ndk-build
or cmake
Upvotes: 1
Reputation: 61380
EDIT: Michael's APP_OPTIM
is better. Once he writes it up, I'll accept. For now, I'll leave this here.
Couldn't find a built-in variable, did a Gradle trick:
buildTypes {
release {
externalNativeBuild {
ndkBuild {
arguments "BUILD_TYPE=release"
}}
}
debug {
externalNativeBuild {
ndkBuild {
arguments "BUILD_TYPE=debug"
}}
}
}
Then the line in Android.mk becomes:
LOCAL_SRC_FILES := $(FOOPROJECT)\foo\build\intermediates\ndkBuild\$(BUILD_TYPE)\obj\local\$(TARGET_ARCH_ABI)\libfoo.a
Upvotes: 2