Android Library Gradle版本JAR

如何发布android-library项目的Jar包装?

我发现,classes.jar位于下面build/bundles/release/classes.jar,我想这是正确的Jar包(包含*.class文件)。


有什么正式的方法可以将库发布为JAR而不是AAR?





慕村225694
浏览 657回答 3
3回答

浮云间

仅仅因为先前的答案不符合我的需求,所以我分享了一些棘手的版本,以使用项目类和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) {&nbsp; &nbsp; from {&nbsp; &nbsp; &nbsp; &nbsp; List<File> allFiles = new ArrayList<>();&nbsp; &nbsp; &nbsp; &nbsp; configurations.compile.collect {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (File f : zipTree(it).getFiles()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (f.getName().equals("classes.jar")) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allFiles.addAll(zipTree(f).getAt("asFileTrees").get(0).getDir())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; allFiles.add(new File('build/intermediates/classes/release'))&nbsp; &nbsp; &nbsp; &nbsp; allFiles // To return the result inside a lambda&nbsp; &nbsp; }&nbsp; &nbsp; archiveName( project.ext.appName + '.jar' )}这不能管理构建类型/风格,但是可以进行修改(可以在没有味道的情况下构建构建版本是可以的)。如果您有更聪明或更优雅的解决方案,请分享
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
Android