简体   繁体   English

如何生成包含javadoc的Android * .jar库?

[英]How to generate Android *.jar Library with javadoc included?

I am working an a library project for Android with Android Studio. 我正在使用Android Studio为Android开发一个图书馆项目。 The project contains a javadoc, but when I build a jar file with Gradle and use the library in another project, I cannot access the documentation. 该项目包含一个javadoc,但是当我使用Gradle构建一个jar文件并在另一个项目中使用该库时,我无法访问该文档。

Generating the html javadoc is possible, but not quite convenient. 生成html javadoc是可能的,但不太方便。 I want to have the documentation inside the jar file (which will be shipped to other users) to see it directly, eg using the Android Studio mouse-hover feature on the code. 我希望将jar文件中的文档(将发送给其他用户)直接查看,例如在代码上使用Android Studio鼠标悬停功能。

Is there a way to include the javadoc into the generated jar file? 有没有办法将javadoc包含在生成的jar文件中?

It is not possible to grab sources or javadoc from a compiled jar. 无法从编译的jar中获取源代码或javadoc。

However build systems like gradle and maven support additional jars: If you upload your artifact to eg Maven central, just put an additional jar with a -sources or -javadoc suffix with the respective content in parallel to the main jar. 然而,像gradle和maven这样的构建系统支持额外的jar:如果你将工件上传到例如Maven central,只需添加一个-sources-javadoc后缀的jar,其中相应的内容与主jar并行。

To generate these jars, use the following gradle tasks 要生成这些jar,请使用以下gradle任务

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    failOnError false
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM