【发布时间】:2015-03-06 04:16:51
【问题描述】:
我在Android.mk 文件中定义了一些变量(我为编译器传递了一些标志),但是每次构建我的项目时,Android.mk 都会被覆盖。我假设Gradle 负责,我应该去那里看看? 如何使用我自己的 Android.mk 文件?
背景信息:
Ubuntu 64 位,Android Studio 1.0.1,JDK7。
我已经用O-LLVM NDK 包装了我的NDK 版本,因此正在编辑位于app/build/intermediates/ndk/debug 的Android.mk 文件(它是我的项目目录中唯一的Android.mk 文件),与文档所在的位置不同O-LLVM 给出了例子。
另外,没有Application.mk 文件,所以我再次假设Gradle 负责调用编译器?
更新信息
build.gradle - (应用)
//The following code until the "----" line is the new build.gradle config file
// that disables automatic Android.mk file generation
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.md.helloworld"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName "MyLib"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jni
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
}
// Call regular ndk-build (.cmd) script from the app directory
task ndkBuild(type: Exec) {
commandLine 'ndk-build', '-C', file('src/main/').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
/*
//The following code is the original Android.mk file
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.md.helloworld"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
//The only modified line
ndk {
moduleName "MyLib"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
*/
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := helloWorld
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -static
include $(BUILD_EXECUTABLE)
Application.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
APP_ABI := armeabi
NDK_TOOLCHAIN_VERSION := clang3.4-obfuscator
include $(BUILD_EXECUTABLE)
请注意:我还没有通过任何 cflags,我正在尝试让 Vanilla 构建首先工作
【问题讨论】:
标签: gradle android-ndk android-studio java-native-interface llvm