3 回答
TA贡献1829条经验 获得超4个赞
仅仅因为先前的答案不符合我的需求,所以我分享了一些棘手的版本,以使用项目类和aar / jar依赖项生成一个jar。
// A tricky jar operation, we want to generate a jar files that contains only the required classes used.
// Dependencies are in jar and aar, so we need to open the aar to extract the classes and put all at the same level
// (aar is a zip that contains classes.jar, the latter is a zip that contains .class files)
task jar(type: Jar) {
from {
List<File> allFiles = new ArrayList<>();
configurations.compile.collect {
for (File f : zipTree(it).getFiles()) {
if (f.getName().equals("classes.jar")) {
allFiles.addAll(zipTree(f).getAt("asFileTrees").get(0).getDir())
}
}
}
allFiles.add(new File('build/intermediates/classes/release'))
allFiles // To return the result inside a lambda
}
archiveName( project.ext.appName + '.jar' )
}
这不能管理构建类型/风格,但是可以进行修改(可以在没有味道的情况下构建构建版本是可以的)。
如果您有更聪明或更优雅的解决方案,请分享
添加回答
举报