-
-
Save dEn13L/60b97f63a4cb084c49a4 to your computer and use it in GitHub Desktop.
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
android.libraryVariants.all { variant -> | |
tasks.create(name: "fatJar${variant.name.capitalize()}", type: Jar, dependsOn: assembleRelease) { | |
doFirst { | |
baseName = project.artifactId + "-" + variant.name | |
destinationDir = file('output') | |
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | |
from zipTree(tasks.getByName("package${variant.name.capitalize()}Jar").outputs.files.singleFile) | |
def closure = { file -> | |
if (file.name.endsWith('.aar')) { | |
println file.name | |
List<File> listJarFiles = zipTree(file).findAll { fileInAar -> | |
fileInAar.name.endsWith('.jar') | |
} | |
def listClassesFilesFromJars = listJarFiles.collect { | |
zipTree(it) | |
} | |
listClassesFilesFromJars | |
} else if (file.name.endsWith('.jar')) { | |
return zipTree(file) | |
} | |
} | |
from configurations.compile.files.collect(closure) | |
from configurations.getByName("${variant.name}Compile").files.collect(closure) | |
} | |
} | |
tasks.create(name: "collectJars${variant.name.capitalize()}", type: Copy, dependsOn: assembleRelease) { | |
delete file("output/outputJars${variant.name.capitalize()}") | |
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | |
from tasks.getByName("package${variant.name.capitalize()}Jar").outputs.files.singleFile, { | |
rename 'classes.jar', project.artifactId + "-" + variant.name + "-" + project.version + ".jar" | |
} | |
def closure = { file -> | |
if (file.name.endsWith('.aar')) { | |
println file.name | |
zipTree(file).findAll { fileInAar -> | |
fileInAar.name.endsWith('.jar') | |
}.each { f -> | |
if(f.name == "classes.jar") { | |
from f, { | |
println f.name | |
rename "classes", file.name.substring(0, file.name.lastIndexOf(".")) | |
} | |
} else { | |
from f | |
} | |
} | |
} else if (file.name.endsWith('.jar')) { | |
from file | |
} | |
} | |
configurations.compile.files.collect(closure) | |
configurations.getByName("${variant.name}Compile").files.collect(closure) | |
into 'output/outputJars' + variant.name.capitalize() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment