Skip to content

Instantly share code, notes, and snippets.

@khernyo
Created December 6, 2012 18:39
Show Gist options
  • Save khernyo/4226923 to your computer and use it in GitHub Desktop.
Save khernyo/4226923 to your computer and use it in GitHub Desktop.
Gradle Android configuration with .so hack
// This hack works with com.android.tools.build:gradle:0.2, won't work in later version without modification
apply plugin: 'android'
targetCompatibility = 1.6
sourceCompatibility = 1.6
android {
target = 'android-14'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDir 'src'
res.srcDir 'res'
assets.srcDir 'assets'
resources.srcDir 'src'
}
test {
java.srcDir 'tests/src'
}
}
}
dependencies {
compile project(':main')
compile fileTree(dir: '../main/libs', include: '*.jar')
compile fileTree(dir: '../thirdparty/actionbar-sherlock/library/libs', include: '*.jar')
}
task copyNativeLibs(type: Copy) {
from(new File(project(':main').buildDir, 'native-libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.PackageApplicationTask) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
@dhesson
Copy link

dhesson commented Jun 27, 2014

@anderkonzen I'm trying to build an AAR. Does the PackageApplication task only kick in if your building an APK?

Currently I build the ndk libs and copy them over to src/main/jniLibs prior to AAR packaging, but I would much rather copy the jni libs into the build dir and have them packaged up from there

@Avinash-Bhat
Copy link

@jjhesk, also take a look at murphy's sample: https://github.com/commonsguy/sqlcipher-gradle

@SeanZoR
Copy link

SeanZoR commented Dec 9, 2014

There's a fix in the new Android Studio 1.0.0 / Gradle 1.0.0:
https://gist.github.com/SeanZoR/cd2ecd22be3fdef7aa09/294bf0dd17a3fe58f23e37bbbe6b4d8d2e6efc37

@trinadhkoya
Copy link

@brimanning it works great ||Thanks a ton

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