我想使用android studio将一个库项目创建到一个jar文件中,该文件包含许多jar文件和像这样的库项目:
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')
}
如何制作包含所有这些依赖项和自己的类文件的jar文件?
答案 0 :(得分:2)
最后,我找到了解决方案:
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);
}