My native library contains logs which I would like to remove at compile time.
Logs are shown by defining the pre-processor macro ENABLE_DEBUG
in LOCAL_CFLAGS
like so:
include $(CLEAR_VARS)
LOCAL_MODULE := native-stuff
LOCAL_SRC_FILES := Native.cpp
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS := -DENABLE_DEBUG
include $(BUILD_SHARED_LIBRARY)
I'm building the app with Gradle via Android Studio and I would like to have another Android.mk file without LOCAL_CFLAGS := -DENABLE_DEBUG
for release builds, effectively disabling logging.
I tried to do it by creating the folders release/jni
under src
and put a copy of Android.mk without the CFLAGS. It builds and deploys successfully, but I still see the logs. Here is my build.gradle
:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
sourceSets {
main {
//Tell Gradle where to put the compiled shared library
jniLibs.srcDir 'src/main/libs'
//disable automatic ndk-build call
jni.srcDirs = [];
}
release {
jni.srcDirs = [];
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Tell Gradle the run the ndkBuild task when compiling
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
// This task utilizes the Android.mk file defined in src/main/jni so that you
// have more control over the build parameters (like library inclusion)
// The system must define property 'androidNdkHome' in ~/.gradle/gradle.properties file
// to point to NDK path
task ndkBuild(type: Exec) {
commandLine "$androidNdkHome/ndk-build", '-C', file('src/main/jni').absolutePath
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.2'
}
My project structure looks like this:
src/
main/
jni/
Android.mk
release/
jni/
Android.mk
Is it possible to do what I want?