Skip to content

Instantly share code, notes, and snippets.

@qrtt1
Last active May 19, 2020 16:09
Show Gist options
  • Save qrtt1/25a44fa29e46a5ec7f5b to your computer and use it in GitHub Desktop.
Save qrtt1/25a44fa29e46a5ec7f5b to your computer and use it in GitHub Desktop.
gradle: package *.jar into aar
project.projectsEvaluated {
def isAndroidLibraryProject = project.plugins.hasPlugin('com.android.library')
if(isAndroidLibraryProject) {
task copyDeps(type:Copy) {
from configurations.compile
into "./build/intermediates/bundles/release/libs/"
}
preBuild.dependsOn copyDeps
task copyDebugDeps(type:Copy) {
from configurations.compile
into "./build/intermediates/bundles/debug/libs/"
}
preDebugBuild.dependsOn copyDebugDeps
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
}
gradle.projectsEvaluated {
["", "Debug"].each { taskId ->
task "copy${taskId}Deps"(type:Copy) {
from configurations.compile
def target = "copyDeps" == name ? "release" : "debug"
def dir = "./build/intermediates/bundles/$target/libs/"
into dir
}
tasks["pre${taskId}Build"].dependsOn "copy${taskId}Deps"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment