android studio 直接编译JNI

tasks.withType(JavaCompile) {

compileTask -> compileTask.dependsOnndkBuild

}

task ndkBuild(type: Exec) {

workingDir file("jni")

commandLinegetNdkBuildCmd()

}

task cleanNative(type: Exec){

workingDir file("jni")

commandLinegetNdkBuildCmd(),"clean"

}

clean.dependsOncleanNative

defgetNdkDir() {

if(System.env.ANDROID_NDK_ROOT !=null)

returnSystem.env.ANDROID_NDK_ROOT

Properties properties =newProperties()

properties.load(project.rootProject.file("local.properties").newDataInputStream())

defndkdir = properties.getProperty("ndk.dir",null)

if(ndkdir ==null)

throw newGradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")

returnndkdir

}

defgetNdkBuildCmd() {

defndkbuild =getNdkDir() +"/ndk-build"

//    ndkbuild+=".cmd" //mac 屏蔽这句

returnndkbuild

}

你可能感兴趣的:(android studio 直接编译JNI)