Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
This article also participated in the “Digitalstar Project” to win a creative gift package and creative incentive money
Summary of a.
We know that Android projects written in Java code can be automatically generated using the Tools — > Generate JavaDoc that comes with Android Studio. What about Android Studio projects written in Kotlin and Android projects developed in a hybrid of Kotlin and Java? Can JavaDoc generation tools automatically generate documentation? Answer: No
Ii. Kotin project document generation tool Dokka
Does Android Studio come with tools that can generate documentation?
Generate JavaDoc, which comes with Android Studio, can Generate parts of Java code in both pure Java projects and kotkin/Java hybrid projects
Unable to generate project document for Kotlin code input
How does the Kotlin project generate documentation
- Here you can use Dokka, a document generation tool on GitHub
- Dokka can not only generate pure Kotlin projects
- You can also generate kotlin and Java hybrid projects and generate documentation
- Dokka supports multiple output formats (HTML, Javadoc, MarkDown..)
Iii. Configuration of Dokka in the project
1. Add the repository and dependencies in build.gradle of project
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
/ / or jcenter (). } dependencies { ...... classpath'org. Jetbrains. Dokka: dokka - gradle - plugin: 0.10.1'}}Copy the code
2. Add the plugin and configure dokka parameters in build.gradle of app
apply plugin: 'org.jetbrains.dokka'
android {
......
dokka {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/dokka"
configuration {
// Do not output deprecated members
skipDeprecated = true
// Emit warnings about not documented members.
reportUndocumented = true
// Do not create index pages for empty packages
skipEmptyPackages = true
noJdkLink = true
noStdlibLink = true
noAndroidSdkLink = true
}
}
}
dependencies {
......
}
Copy the code
After the configuration is complete as shown in the preceding figure, the sync synchronization project is complete
How to use Dokka to generate documents
4.1 Through dokka in Document in the right Gradle window
- Open the Gradle window on the right and pass
Project name --> APP --> Tasks --> Documentation --> Dokka
Find the task,Double click on the
Run the task
Graph LR 1 {{Gradle window}} - > [project] -- > B (app) -- -- > C [Tasks] [documentation] -- > > D E {dokka}
4.2 In the Terminal window, enter./gradlew dokka to run the task
- Open the Terminal window at the bottom and enter gradlew dokka in the window to execute the task
5. View Dokka generated documents
Open it in order: Project – >app – > Build – >dokka(build. Gradle config build folder) – > right-click to open index.html in your browser