8

I'm trying to use the dokka plugin in my Kotlin project, but I'm getting the following message:

Error:(7, 0) Plugin with id 'org.jetbrains.dokka' not found.

I'm using Android Studio version 3.0.

Thanks in advance.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Melchior
  • 259
  • 1
  • 5
  • 15
  • have you added dependencies { classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}" } and make sure gradle isn't in offline mode – humazed Nov 08 '17 at 03:17
  • 1
    Yes add the dependencies but I'm getting the following error: Error:(13, 0) Could not get unknown property 'dokka_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. – Melchior Nov 08 '17 at 09:39
  • @Melchior did you ever figure out the problem? The solutions below is nothing but the instructions that you (and I) already followed. There is another step missing. What is that? – portfoliobuilder Aug 06 '19 at 16:27

5 Answers5

4

Using Dokka with Kotlin in Android Studio for the first time

#1. Settings

##1.1 Settings in 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)

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. Building the docs

##2.1 Your code should contain comments. Take a look at the following link, in order to get more details: 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. --> MyProject --> app --> Tasks --> DocsByDokka

enter image description here

Gradle-Window in Android Studio

##2.3 Generate Docs Double Click on DocsByDokka in the Gradle-Window.

#3. Find the docs ##3.1 Go to your Project-Folder Select the Project and not the Android view. I find this by default at the left corner of Android Studio. --> MyProject --> app --> build --> dokka --> app There you are going to find index.html. Right-click and select "Open in Browser".

3

So, when I ran into the issue, example I was reading, did not specify exactly where to put dokka dependencies. Once I figured those out, the project compiled and build:

build.gradle (Project level file):

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):

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"
    }
}
mike.tihonchik
  • 6,855
  • 3
  • 32
  • 47
0

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:

apply plugin: 'org.jetbrains.dokka-android'

and

classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}"

as pointed out in the Android section of the Dokka GitHub page.

colbadhombre
  • 803
  • 8
  • 11
0

when running android apply plugin: 'org.jetbrains.dokka-android'
result is Plugin with id 'org.jetbrains.dokka-android' not found.

so change to org.jetbrains.dokka is working

xuming liu
  • 11
  • 3
-1

You can generate Dokka documentatiton without Dokka plugin... Use EasyDokkaPlugin

Add the following at the end of build.gradle of each sub-module that you wish to generate documentation:

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

You can now generate documentation by Dokka documentation engine in Javadoc format:

$ gradle dokkaJavadocsJar
Alexander Savin
  • 1,952
  • 1
  • 15
  • 30