简体   繁体   English

在 Android studio 3 中找不到 Dokka 插件

[英]Dokka plugin not found in Android studio 3

I'm trying to use the dokka plugin in my Kotlin project, but I'm getting the following message:我正在尝试在我的 Kotlin 项目中使用 dokka 插件,但我收到以下消息:

Error:(7, 0) Plugin with id 'org.jetbrains.dokka' not found.错误:(7, 0) 未找到 ID 为“org.jetbrains.dokka”的插件。

I'm using Android Studio version 3.0.我正在使用 Android Studio 3.0 版。

Thanks in advance.提前致谢。

Using Dokka with Kotlin in Android Studio for the first time首次在 Android Studio 中将 Dokka 与 Kotlin 结合使用

#1. #1. Settings设置

##1.1 Settings in build.gradle(Project) ##1.1 build.gradle(Project) 中的设置

buildscript {
    ext {
        version_dokka = "0.10.0"
        version_gradle = "3.5.2"
        version_kotlin = "1.3.41"
        ...
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$version_gradle"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:${version_dokka}"
        ...
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

##1.2 Settings in build.gradle(Module:app) ##1.2 build.gradle(Module:app)中的设置

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    ...
    // Dokka used for auto-generation documentation
    dokka {
        outputFormat = 'html'
        //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
        }
    }
}

// workaround: create DocsByDokka
task DocsByDokka (type: org.jetbrains.dokka.gradle.DokkaTask) {
    outputFormat = "html"
    outputDirectory = "$buildDir/dokka"
}

Don't forget to sync不要忘记同步

#2. #2. Building the docs构建文档

##2.1 Your code should contain comments. ##2.1 你的代码应该包含注释。 Take a look at the following link, in order to get more details: https://kotlinlang.org/docs/reference/kotlin-doc.html请查看以下链接以获取更多详细信息: https : //kotlinlang.org/docs/reference/kotlin-doc.html

##2.2 Go to the Gradle-Window in Android Studio I have to click on "Gradle" at the right top corner in Android Studio 3 After clicking on "Gradle" a window opens. ##2.2 转到Android Studio 中的Gradle-Window 我必须点击Android Studio 3 右上角的“Gradle” 点击“Gradle”后会打开一个窗口。 --> MyProject --> app --> Tasks --> DocsByDokka --> 我的项目 --> 应用程序 --> 任务 --> DocsByDokka

在此处输入图片说明

Gradle-Window in Android Studio Android Studio 中的 Gradle 窗口

##2.3 Generate Docs Double Click on DocsByDokka in the Gradle-Window. ##2.3 生成文档在 Gradle 窗口中双击 DocsByDokka。

#3. #3. Find the docs ##3.1 Go to your Project-Folder Select the Project and not the Android view.查找文档 ##3.1 转到您的项目文件夹 选择项目而不是 Android 视图。 I find this by default at the left corner of Android Studio.默认情况下,我在 Android Studio 的左角找到了它。 --> MyProject --> app --> build --> dokka --> app There you are going to find index.html . --> MyProject --> app --> build --> dokka --> app 在那里你会找到index.html Right-click and select "Open in Browser".右键单击并选择“在浏览器中打开”。

index.html in project view项目视图中的 index.html

So, when I ran into the issue, example I was reading, did not specify exactly where to put dokka dependencies.因此,当我遇到这个问题时,例如我正在阅读的示例,并没有具体说明将dokka依赖项放在dokka Once I figured those out, the project compiled and build:一旦我想通了这些,项目就会编译并构建:

build.gradle (Project level file): build.gradle(项目级文件):

buildscript {
    ext.kotlin_version = '1.2.51'
    ext.kotlin_version = '1.2.30'
    ext.dokka_version = '0.9.17'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

build.gradle (Module level file): build.gradle(模块级文件):

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.dokka-android'

android {
    compileSdkVersion 27

    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
...

    dokka {
        outputFormat = 'javadoc'
        outputDirectory = "$buildDir/javadoc"
    }
}

When running Dokka on Android code, you need to use the versions of the plugin specific to Android, instead of the stand-alone Gradle forms:在 Android 代码上运行 Dokka 时,您需要使用特定于 Android 的插件版本,而不是独立的 Gradle 形式:

apply plugin: 'org.jetbrains.dokka-android'应用插件:'org.jetbrains.dokka-android'

and

classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}"类路径“org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}”

as pointed out in the Android section of the Dokka GitHub page.正如 Dokka GitHub 页面的 Android 部分所指出的那样。

when running android apply plugin: 'org.jetbrains.dokka-android'运行 android apply plugin: 'org.jetbrains.dokka-android'
result is Plugin with id 'org.jetbrains.dokka-android' not found.结果是未找到 ID 为“org.jetbrains.dokka-android”的插件。

so change to org.jetbrains.dokka is working所以更改为org.jetbrains.dokka是有效的

You can generate Dokka documentatiton without Dokka plugin... Use EasyDokkaPlugin您可以在没有 Dokka 插件的情况下生成 Dokka 文档...使用EasyDokkaPlugin

Add the following at the end of build.gradle of each sub-module that you wish to generate documentation:在您希望生成文档的每个子模块的build.gradle末尾添加以下内容:

apply from: 'https://raw.github.com/Vorlonsoft/EasyDokkaPlugin/master/dokka.gradle'

You can now generate documentation by Dokka documentation engine in Javadoc format:您现在可以通过 Dokka 文档引擎以 Javadoc 格式生成文档:

$ gradle dokkaJavadocsJar

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

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