作者:天崖人B | 来源:互联网 | 2023-05-19 12:23
我的本机库包含我想在编译时删除的日志.日志由限定所述预处理器宏所示ENABLE_DEBUG
在LOCAL_CFLAGS
像这样:
include $(CLEAR_VARS)
LOCAL_MODULE := native-stuff
LOCAL_SRC_FILES := Native.cpp
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS := -DENABLE_DEBUG
include $(BUILD_SHARED_LIBRARY)
我正在通过Android Studio使用Gradle构建应用程序,我希望有另一个Android.mk文件,不需要LOCAL_CFLAGS := -DENABLE_DEBUG
发布版本,有效地禁用日志记录.
我尝试通过创建下面的文件夹并在没有CFLAGS的情况release/jni
下src
放置Android.mk的副本来实现.它成功构建和部署,但我仍然看到日志.这是我的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'
}
我的项目结构如下所示:
src/
main/
jni/
Android.mk
release/
jni/
Android.mk
有可能做我想要的吗?