Skip to content

Instantly share code, notes, and snippets.

@kakajika
Last active August 29, 2015 14:12
Show Gist options
  • Save kakajika/da449e21dcb899ed3994 to your computer and use it in GitHub Desktop.
Save kakajika/da449e21dcb899ed3994 to your computer and use it in GitHub Desktop.
Android NDK build script for Gradle. GradleでNDKビルドをするスクリプト。
// ndkbuild.gradle
def useJar = true // libをJar化するかどうか
def jniDir = 'src/main/jni'
android {
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDirs = useJar ? [] : [new File(buildDir, 'libs')]
}
}
}
task ndkBuild(type: Exec) {
def ndkDir = project.plugins.findPlugin('android').getNdkFolder()
commandLine "${ndkDir}/ndk-build",
"NDK_PROJECT_PATH=build",
"APP_BUILD_SCRIPT=${jniDir}/Android.mk",
"NDK_APPLICATION_MK=${jniDir}/Application.mk"
}
task ndkLibsToJar(type: Zip, dependsOn: 'ndkBuild') {
destinationDir new File(buildDir, 'libs')
baseName 'nativelibs'
extension 'jar'
from(new File(buildDir, 'libs')) { include '**/*.so' }
into 'lib/'
}
tasks.withType(AbstractCompile) {
compileTask -> compileTask.dependsOn useJar ? ndkLibsToJar : ndkBuild
}
dependencies {
compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
}
// in build.gradle
apply plugin: 'android'
apply from: './ndkbuild.gradle'
...
// in local.properties
ndk.dir=path/to/ndk/root/directory
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment