Last active
March 3, 2017 02:04
-
-
Save vincent1086/39a0b6142536d21d83de8b19f62fae45 to your computer and use it in GitHub Desktop.
Android library use gradle build .apk / .aar / .jar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////// | |
// 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