Android studio make jar file with dependencies

一世执手 提交于 2019-12-23 03:14:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!