Created
December 17, 2013 13:05
-
-
Save Vandalko/8004598 to your computer and use it in GitHub Desktop.
Android Studio (Gradle) NDK support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////// | |
// NDK Support | |
////////////// | |
task buildNative(type: Exec) { | |
if (System.env.ANDROID_NDK != null) { | |
def ndkBuild = null | |
if (System.properties['os.name'].toLowerCase().contains('windows')) { | |
ndkBuild = new File(System.env.ANDROID_NDK, 'ndk-build.cmd') | |
} else { | |
ndkBuild = new File(System.env.ANDROID_NDK, 'ndk-build') | |
} | |
commandLine ndkBuild, "--directory", file("src/main/jni").absolutePath, "-B", "NDK_DEBUG=0", "V=1" | |
doLast { | |
file('src/main/obj').deleteDir() | |
} | |
} else { | |
doLast { | |
println '##################' | |
println 'Skipping NDK build' | |
println 'Reason: ANDROID_NDK_HOME not set.' | |
println '##################' | |
} | |
} | |
} | |
task copyNativeLibs(type: Copy, dependsOn: 'buildNative') { | |
doFirst { | |
new File(buildDir, 'native-libs').mkdirs() | |
} | |
from(file('src/main/libs')) { include '**/*.so' } | |
into new File(buildDir, 'native-libs') | |
doLast { | |
file('src/main/libs').deleteDir() | |
} | |
} | |
task cleanNativeLibs(type: Delete) { | |
delete 'src/main/obj', 'src/main/libs', 'libs/armeabi' | |
} | |
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> | |
pkgTask.jniDir new File(buildDir, 'native-libs') | |
} | |
gradle.projectsEvaluated { | |
preBuild.dependsOn 'copyNativeLibs' | |
clean.dependsOn 'cleanNativeLibs' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment