[英]How to generate .jar of android library with *class files?
Currently my gradle task looks like:目前我的 gradle 任务看起来像:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
...
}
task sourcesJar(type: Jar) {
getArchiveClassifier().set('sources')
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives sourcesJar
}
But in result jar artifact has *.java
and *.kt
files, but how to generate jar artifact with *.class
files?但是结果 jar artifact 有
*.java
和*.kt
文件,但是如何生成带有*.class
文件的 jar artifact?
Based on your screenshot, you are opening xxx-sources.jar
file.根据您的屏幕截图,您正在打开
xxx-sources.jar
文件。 Of course it contains only Java source file inside.当然它里面只包含Java源文件。 This is the correct result as you configure as below:
这是您配置如下的正确结果:
task sourcesJar(type: Jar) {
getArchiveClassifier().set('sources')
from android.sourceSets.main.java.sourceFiles
}
You classes file normally are separated in another jar file.您的类文件通常被分隔在另一个 jar 文件中。 You didn't specify what are the tasks you executed.
您没有指定您执行的任务是什么。 So let's assume you run the default Android build task, it will generate the
aar
file, it should contain your module classes file.所以让我们假设你运行默认的 Android 构建任务,它会生成
aar
文件,它应该包含你的模块类文件。 You can unzip sapi-1.6.aar
to check.您可以解压
sapi-1.6.aar
进行检查。
You can refer to this doc as well.您也可以参考此 文档。
Updated:更新:
You didn't specify why you need the Jar file instead of AAR file, let's assume you want to use Jar file in other project, then you need to use other gradle plugin to build (can't use android
gradle plugin), it could be java
or base
gradle plugin.您没有说明为什么需要Jar文件而不是AAR文件,假设您想在其他项目中使用Jar文件,那么您需要使用其他gradle插件来构建(不能使用
android
gradle插件),它可以是java
或base
gradle 插件。 Some answer saying, you can find the jar file inside aar file, you can check this .有人回答说,你可以在 aar 文件中找到 jar 文件,你可以检查这个。
From command line, you just type:从命令行,您只需键入:
jar uf0 path_to_your_jar_file\yourJarFile.jar path_to_your_classes\*.class
and of course, you can use the class name instead of a wildcard (*) if you don't want to add all classes from that directory.当然,如果您不想添加该目录中的所有类,您可以使用类名而不是通配符 (*)。
jar --help
will give you more options.会给你更多的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.