问题
I know how use custom Android.mk
with old gradle:
sourceSets.main {
jniLibs.srcDir 'src/main/jni'
jni.srcDirs = [] //disable automatic ndk-build call
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
commandLine '/.../android-ndk-r10e/ndk-build', '-C', file('src/main').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
It's not working with new gradle: com.android.tools.build:gradle-experimental:0.2.0
:
Error:Cause: com.android.build.gradle.managed.AndroidConfig_Impl
回答1:
with the new gradle-experimental plugin, your configuration would be:
model {
//...
android.sources{
main.jni {
source {
srcDirs = ['src/main/none']
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
//...
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
commandLine '/.../android-ndk-r10e/ndk-build', '-C', file('src/main').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
Note that version 0.3.0-alpha7 of the gradle-experimental plugin is out.
回答2:
Add this to your build.gradle file. This will cause the ndk-build
to run as part of project build using the specified .mk file.
android{
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
回答3:
In addition to the previous response: With Experimental Plugin version 0.7.0-alpha1 this works on Windows
model {
// ...
android.sources.main {
jni {
source {
srcDirs = ['src/main/none']
}
}
jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
// ...
}
task ndkBuild(type: Exec) {
def cmdline = "${System.env.ANDROID_NDK_HOME}/ndk-build -C \"" + file('src/main').absolutePath + "\" > ndk-build-log.txt 2>&1"
commandLine 'cmd', '/c', cmdline
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
来源:https://stackoverflow.com/questions/32970094/how-to-use-custom-android-mk-with-new-gradle-build-system