Skip to content

Instantly share code, notes, and snippets.

@maxme
Created November 12, 2013 17:21
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 maxme/7434896 to your computer and use it in GitHub Desktop.
Save maxme/7434896 to your computer and use it in GitHub Desktop.
A gradle build file for Android NDK - uses a trick to put *so files in a jar and add that jar as a project dependency
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
task nativeLibsToJar(
type: Zip,
description: 'create a jar archive of the native libs') {
destinationDir file('./libs')
baseName 'native-libs'
extension 'jar'
from 'libs/'
include '**/*.so'
into 'lib/'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
clean.dependsOn 'cleanNativeLibsToJar'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
task ndkBuild(type:Exec) {
commandLine 'ndk-build'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/native-libs.jar')
}
@Pierozi
Copy link

Pierozi commented Jan 19, 2015

small note, now the keyword Compile at tasks.withType(Compile) is deprecated, you need to use JavaCompile like this tasks.withType(JavaCompile)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment