Skip to content

Instantly share code, notes, and snippets.

@dylanPowers
Created October 10, 2013 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanPowers/6914381 to your computer and use it in GitHub Desktop.
Save dylanPowers/6914381 to your computer and use it in GitHub Desktop.
A sample build.gradle script that incorporates the Android NDK. This differs from a lot of samples out there because it makes use of the new default directory setup.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 16
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 16
}
}
// NDK build support
task buildNative(type: Exec) {
// A lot of samples don't specify the build directory.
commandLine 'ndk-build', '-C', 'src/main'
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn 'buildNative' }
clean.dependsOn 'cleanNative'
task cleanNative(type: Exec) {
commandLine 'ndk-build', 'clean', '-C', 'src/main'
}
// Copies the libs to the apk.
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniDir new File(projectDir, 'src/main/libs')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment