Created
December 17, 2013 08:00
-
-
Save twocity/8001549 to your computer and use it in GitHub Desktop.
gradle ndk build
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 | |
////////////// | |
// If using this, Android studio will fail run the following to set the environment variable for android studio: | |
// export ANDROID_NDK_HOME=/Android/android-ndk-r8e (Linux) | |
// launchctl setenv ANDROID_NDK_HOME /Android/android-ndk-r8e (Mac) | |
// or, better, add the export to the .profile of your user home and re-login | |
task copyNativeLibs(type: Copy, dependsOn: 'buildNative') { | |
from(new File('src/main/libs')) { include '**/*.so' } | |
into new File(buildDir, 'native-libs') | |
} | |
// TODO fix deprecated | |
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs } | |
clean.dependsOn 'cleanCopyNativeLibs' | |
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> | |
pkgTask.jniDir new File(buildDir, 'native-libs') | |
} | |
task buildNative(type: Exec, dependsOn: "ndkCheck") { | |
def ndkBuild; | |
def ndkBuildingDir = new File("src/main/jni"); | |
// def ndkSourcesDir = new File(ndkBuildingDir, "jni") | |
// def ndkOutputDir = new File(buildDir, 'native-libs') | |
ndkBuild = new File("$System.env.ANDROID_NDK_HOME", 'ndk-build') | |
// inputs.files fileTree(ndkSourcesDir) | |
// outputs.dir ndkOutputDir | |
commandLine ndkBuild, "--directory", ndkBuildingDir | |
} | |
task cleanNative(type: Exec, dependsOn: "ndkCheck") { | |
def ndkBuild; | |
def ndkBuildingDir = new File("src/main/jni"); | |
ndkBuild = new File("$System.env.ANDROID_NDK_HOME", 'ndk-build') | |
commandLine ndkBuild, "--directory", ndkBuildingDir, "clean" | |
} | |
task ndkCheck { | |
def hasNdk = false; | |
if (System.getenv("ANDROID_NDK_HOME") != null) { | |
hasNdk = true; | |
} | |
def home = "${System.env.ANDROID_NDK_HOME}" | |
if (home != null) { | |
hasNdk = true; | |
println home | |
println System.getenv()['JAVA_HOME'] | |
println System.getenv()['ANDROID_HOME'] | |
logger.error('##################') | |
} | |
if (!hasNdk) { | |
logger.error('##################') | |
logger.error("Failed NDK build") | |
logger.error('Reason: Reason: ANDROID_NDK_HOME not set.') | |
logger.error('##################') | |
} | |
assert hasNdk: "ANDROID_NDK_HOME not set." | |
} | |
clean.dependsOn 'cleanNative' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment