问题
I want to use android studio to make a library project to a jar file which contains many jar files and library projects like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':app:libraries:MyLibrary:app')
compile 'com.luckycatlabs:SunriseSunsetCalculator:1.2'
compile project(':app:libraries:MyLibrary:app:libraries:MySubLibrary:app')
}
How can I make a jar file with all this dependencies and own class files?
回答1:
Finally, I found the solution:
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);
}
来源:https://stackoverflow.com/questions/36001814/android-studio-make-jar-file-with-dependencies