作者:舞动青春的迪斯科舞厅 | 来源:互联网 | 2023-05-27 19:30
我在Android.mk
文件中定义了一些变量(我正在为编译器传递一些标志),但每次构建我的项目时,都会Android.mk
被覆盖.我假设这Gradle
是负责任的,我应该在那里看?我如何使用自己的Android.mk文件?
背景资料:
Ubuntu
64位,Android Studio
1.0.1,JDK7.我NDK
用O-LLVM NDK封装了我的版本,因此正在编辑Android.mk
位于app/build/intermediates/ndk/debug
(它是Android.mk
我项目目录中唯一的文件)的文件,与doc O-LLVM
提供示例的位置不同.
此外,没有Application.mk
文件,所以我再次假设Gradle
负责调用编译器?
任何帮助将不胜感激.
凯尔
更新的信息
build.gradle - (app)
//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构建首先工作
1> ph0b..:
是的,默认情况下,gradle android插件重新生成并使用自己的Android.mk文件来编译源代码.
您可以取消激活它并使用您自己的Android.mk文件,方法是在build.gradle配置文件中设置:
import org.apache.tools.ant.taskdefs.condition.Os
...
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jniLibs
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
请注意,如果您只需要将自己的cflags传递给自动生成的Makefile,则可以在cFlags ""
属性中设置这些内容以设置内部android { ndk {}}