Skip to content

Instantly share code, notes, and snippets.

@vincent1086
Last active March 3, 2017 02:04
Show Gist options
  • Save vincent1086/39a0b6142536d21d83de8b19f62fae45 to your computer and use it in GitHub Desktop.
Save vincent1086/39a0b6142536d21d83de8b19f62fae45 to your computer and use it in GitHub Desktop.
Android library use gradle build .apk / .aar / .jar
////////////////////////////////
// import library (.aar / .jar)
////////////////////////////////
repositories {
jcenter()
mavenCentral()
mavenLocal()
flatDir{
dirs 'libs'
}
}
dependencies {
// ...other library
compile(name:'lib-debug', ext:'aar')
}
//////////////
// build .aar
/////////////
task copyAar(type : Copy){
from('build/outputs/aar')
include('**/*.aar')
into('../app/libs/')
}
///////////////
// build .apk
//////////////
task copyApks(type: Copy) {
from('build/outputs/apk') {
exclude '**/*unsigned.apk', '**/*unaligned.apk'
}
into '../app/libs'
}
///////////////
// build .jar
//////////////
task createJar(type : Copy) {
from('build/intermediates/bundles/release')
into('libs/')
include('classes.jar')
rename('classes.jar', 'mylib.jar')
}
///////////////
// delete .jar
//////////////
task deleteJar(type : Delete) {
delete 'libs/mylib.jar'
}
////////////////////////////////////
// build .jar before run build task
///////////////////////////////////
createJar.dependsOn(deleteJar, build)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment