Skip to content

Instantly share code, notes, and snippets.

@kesco
Forked from kellyfj/Gradle Android Jar Library
Last active August 15, 2018 06:45
Show Gist options
  • Save kesco/77132337ab0d8dc81016 to your computer and use it in GitHub Desktop.
Save kesco/77132337ab0d8dc81016 to your computer and use it in GitHub Desktop.
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
return; // Skip debug builds.
}
def task = project.tasks.create "jar${name.capitalize()}", Jar
task.dependsOn variant.javaCompile
//Include Java classes
task.from variant.javaCompile.destinationDir
//Include dependent jars with some exceptions
task.from configurations.compile.findAll {
it.getName() != 'android.jar' && !it.getName().startsWith('junit') && !it.getName().startsWith('hamcrest')
}.collect {
it.isDirectory() ? it : zipTree(it)
}
artifacts.add('archives', task);
}
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
return; // Skip debug builds.
}
def task = project.tasks.create "jar${name.capitalize()}", Jar
task.dependsOn variant.javaCompile
//Include Java classes
task.from variant.javaCompile.destinationDir
artifacts.add('archives', task);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment