我今天开始使用Gradle,在搜索了一个小时并尝试了SO(例如1)和不同博客(例如2)和文档(例如3)的每个可能答案后,我需要一些帮助.
我的问题很简单:如何执行自定义构建步骤(在我的情况下,使用自定义的Android.mk执行ndk-build)作为常规构建过程的一部分?
build.gradle看起来像这样:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "myApp.prototype"
minSdkVersion 16
targetSdkVersion 19
testApplicationId "myApp.prototype.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets.main.jni.srcDirs = []
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def ndkDir = properties.getProperty('ndk.dir')
println ndkDir
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir\\ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs', …Run Code Online (Sandbox Code Playgroud) android gradle android-ndk build.gradle android-gradle-plugin