Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dokka showing <Error class: unknown class> for classes generated by data binding #2821

Open
MikeAde1 opened this issue Jan 19, 2023 · 10 comments
Labels
bug platform: android-jvm An issue/PR that has some Android platform specifics

Comments

@MikeAde1
Copy link

MikeAde1 commented Jan 19, 2023

Describe the bug
Whenever I run dokka to generate documentation for a class with a type parameter that extends ViewDataBinding,
I get this error: <Error class: unknown class> for that particular class.

Expected behaviour
I expect that if that class doesn't exist, it should just be rendered as a plain text rather than that error

Dokka configuration
In the root build.gradle file, I'm importing dokka this way,

dependencies {
     classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.7.20"
}

apply plugin: "org.jetbrains.dokka"

tasks.named("dokkaHtmlMultiModule").configure {
    dependencies {
        dokkaPlugin("com.glureau:html-mermaid-dokka-plugin:$mermaid_dokka_version")
    }

    includes.from("dokka-documentation.md")
    suppressInheritedMembers.set(true)

    def imagesList = []
    fileTree("${projectDir}/resources").matching {
        include(["*.png"])
    }.each {imagesList.add("\"$it.absolutePath\"") }

    pluginsMapConfiguration.set(
            [
                "org.jetbrains.dokka.base.DokkaBase": """{
                    "customAssets": $imagesList
                }"""
            ]
    )
}

Also I'm applying a Gradle file(subprojects.gradle) into the root-level build.gradle

subprojects {
    // Add dokka plugin to each module
    apply plugin: "org.jetbrains.dokka"

    // mermaid markdown
    dependencies {
        dokkaPlugin("com.glureau:html-mermaid-dokka-plugin:$mermaid_dokka_version")
    }

    // override dokkaHtml task
    tasks.named("dokkaHtml") {
        // Add custom naming format for modules
        moduleName.set("${project.name.capitalize()} Module")
        // Set suppressInheritedMembers to true in both the tasks
        suppressInheritedMembers.set(true)

        dokkaSourceSets {
            named("main") {
                noAndroidSdkLink.set(false)
                includes.from("module.md")
            }
        }
    }

    // override dokkaHtmlPartial task
    tasks.named("dokkaHtmlPartial") {
        moduleName.set("${project.name.capitalize()} Module")
        suppressInheritedMembers.set(true)

        dokkaSourceSets {
            named("main") {
                noAndroidSdkLink.set(false)
                includes.from("module.md")
            }
        }
    }
}
  
kotlin_version = '1.6.21'

Installation

  • Operating system: macOS
  • Build tool: Gradle v7.0.4
  • Dokka version: 1.7.20

Screen Shot 2023-01-20 at 4 11 33 PM

@MikeAde1 MikeAde1 added the bug label Jan 19, 2023
@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Jan 19, 2023

Hm, it looks like Dokka is unable to find the class for some reason.

Some questions

  • Does the class come from a dependency? Can you say which?
  • Does it happen if you use it in some other place - for instance, as a function parameter
  • Can you try using classes from the same library/package to see if they also behave the same way?

@MikeAde1
Copy link
Author

MikeAde1 commented Jan 20, 2023

Hm, it looks like Dokka is unable to find the class for some reason.

Some questions

  • Does the class come from a dependency? Can you say which?
  • Does it happen if you use it in some other place - for instance, as a function parameter
  • Can you try using classes from the same library/package to see if they also behave the same way?

It comes from the generated classes for databinding layout files. For instance, ActivityMainBinding is generated for activity_main.xml layout file

It happens in any other place that the databinding generated class is being used

Generated classes from the databinding framework also produce this error

@MikeAde1
Copy link
Author

Hm, it looks like Dokka is unable to find the class for some reason.
Some questions

  • Does the class come from a dependency? Can you say which?
  • Does it happen if you use it in some other place - for instance, as a function parameter
  • Can you try using classes from the same library/package to see if they also behave the same way?

It comes from the generated classes for databinding layout files. For instance, ActivityMainBinding is generated for activity_main.xml layout file

It happens in any other place that the databinding generated class is being used

Generated classes from the databinding framework also produce this error

Any update on this?

@lauzadis
Copy link
Contributor

Related to: #503

@IgnatBeresnev
Copy link
Member

It comes from the generated classes

Oh, this might be because generated files are suppressed by default for some reason.

Try setting suppressGeneratedFiles configuration option to false. You can find an example in documentation: https://kotlinlang.org/docs/dokka-gradle.html#source-set-configuration

@MikeAde1
Copy link
Author

MikeAde1 commented Feb 1, 2023

It comes from the generated classes

Oh, this might be because generated files are suppressed by default for some reason.

Try setting suppressGeneratedFiles configuration option to false. You can find an example in documentation: https://kotlinlang.org/docs/dokka-gradle.html#source-set-configuration

I tried this, however it didn't work for me. It happens that the generated files are under this directory app/build/generated/data_binding_base_class_source_out.

Screenshot below

Screen Shot 2023-02-01 at 10 09 51 AM

Is it possible to configure dokka to also read files from this directory?

@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Feb 8, 2023

I'm surprised suppressGeneratedFiles didn't help. Did you try setting it for all source sets, not only main? I'm not sure how the generated sources are resolved under the hood. From your configuration example:

// override dokkaHtmlPartial task
tasks.named("dokkaHtmlPartial") {
    moduleName.set("${project.name.capitalize()} Module")
    suppressInheritedMembers.set(true)

    dokkaSourceSets {
        named("main") {
            noAndroidSdkLink.set(false)
            includes.from("module.md")
        }
    }

    // this has been added
    configureEach {
        suppressGeneratedFiles.set(false)
    }
}

@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Feb 8, 2023

In case it still doesn't work, it might be that they are somehow not picked up properly..?

Is it possible to configure dokka to also read files from this directory?

Try setting the sourceRoots.from(...) configuration option, to which you can pass the directory with the generated sources. Some more context can be found in the documentation: https://kotlinlang.org/docs/dokka-gradle.html#source-set-configuration

@MikeAde1
Copy link
Author

MikeAde1 commented Feb 13, 2023

I'm surprised suppressGeneratedFiles didn't help. Did you try setting it for all source sets, not only main? I'm not sure how the generated sources are resolved under the hood. From your configuration example:

// override dokkaHtmlPartial task
tasks.named("dokkaHtmlPartial") {
    moduleName.set("${project.name.capitalize()} Module")
    suppressInheritedMembers.set(true)

    dokkaSourceSets {
        named("main") {
            noAndroidSdkLink.set(false)
            includes.from("module.md")
        }
    }

    // this has been added
    configureEach {
        suppressGeneratedFiles.set(false)
    }
}

Yeah. I used this configuration exactly this way but it didn't work. It seems suppressGeneratedFiles config does not work as described in this documentation.

@MikeAde1
Copy link
Author

In case it still doesn't work, it might be that they are somehow not picked up properly..?

Is it possible to configure dokka to also read files from this directory?

Try setting the sourceRoots.from(...) configuration option, to which you can pass the directory with the generated sources. Some more context can be found in the documentation: https://kotlinlang.org/docs/dokka-gradle.html#source-set-configuration

I've tried this alternative. This output here shows that the generated files are saved under another directory apart from the main directory. However, the files in the main directory cannot recognize the generated files housed under the separate directory so the error still shows.

Screen Shot 2023-02-13 at 3 45 41 PM

To experiment something else, instead of passing the directory path of the generated files as the sourceRoots parameter, I passed the file path of one class and that worked fine:

sourceRoots.from("$buildDir/generated/../databinding/ActivityMainBinding.java")

Since there could be many files under the generated folder, adding the sourceRoots config for each file does not seem efficient.

@IgnatBeresnev IgnatBeresnev added the platform: android-jvm An issue/PR that has some Android platform specifics label Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform: android-jvm An issue/PR that has some Android platform specifics
Projects
None yet
Development

No branches or pull requests

3 participants