说明:Android studio特殊性,win32客户端无法使用Cmake,但是Linux以及WIN64客户端可以使用Cmake,所以NDK开发针对Linux以及WIN64有几个方法
1. 使用google推荐的cmake
2. 使用传统方式
Cmake NDK开发案例:https://github.com/googlesamples/android-ndk
传统NDK开发配置跟WIN32大体一样
区别在于LINUX平台编译文件为ndk-build windows平台为ndk-build.cmd
**Linux:**
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
println('executing ndkBuild')
def ndkBuildPath = android.ndkDirectory;
commandLine "$ndkBuildPath/ndk-build", '-j8', '-C', file('src/main').absolutePath
}
task ndkClean(type: Exec, description: 'clean JNI libraries') {
println('executing ndkBuild clean')
def ndkBuildPath = android.ndkDirectory;
commandLine "$ndkBuildPath/ndk-build", 'clean', '-C', file('src/main').absolutePath
}
clean.dependsOn 'ndkClean'
---------------------------------------------------------------
**window:**
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
println('executing ndkBuild')
def ndkBuildPath = android.ndkDirectory;
commandLine "$ndkBuildPath/ndk-build.cmd", '-j8', '-C', file('src/main').absolutePath
}
task ndkClean(type: Exec, description: 'clean JNI libraries') {
println('executing ndkBuild clean')
def ndkBuildPath = android.ndkDirectory;
commandLine "$ndkBuildPath/ndk-build.cmd", 'clean', '-C', file('src/main').absolutePath
}
clean.dependsOn 'ndkClean'