Skip to content

Instantly share code, notes, and snippets.

@MaTriXy
Forked from kellyfj/Gradle Android Jar Library
Last active August 29, 2015 14:27
Show Gist options
  • Save MaTriXy/8641c54131e6f5bd6940 to your computer and use it in GitHub Desktop.
Save MaTriXy/8641c54131e6f5bd6940 to your computer and use it in GitHub Desktop.
Using the Android Library plugin for Gradle - create a .jar file (in addition to a .aar library file) that contains all the classes (and dependent jar files). Solution is based off a combination of solutions from https://gist.github.com/Lien/7150489 and the Winning answer to this Stackoverflow Question http://stackoverflow.com/questions/19307341…
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals(com.android.builder.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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment