error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass()
Asked Answered
V

1

32

I am trying to generate Doka docs of my project. While generating I am getting an error like above. I have searched so many but could not able to get solution to this. I have gone through this link also. Here it is saying it might be a dagger related issue. I have tried these all solution also but not worked for me. I am posting here my all Gradle files for more clarification. if any one faced this issue or know the way to solve Please do comments.

Project Gradle :

 buildscript {
        ext.kotlin_version = '1.3.20'
        ext.dokkaVersion = '0.9.17'
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.3.1'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokkaVersion"
            classpath "org.jetbrains.kotlin:kotlin-allopen:1.3.20"

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

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

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

App Gradle :

    apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

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

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.xx.xxx.xxx"
        minSdkVersion 23
        multiDexEnabled true
        targetSdkVersion 28
        versionCode 1
        versionName "1.0.3"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    dokka {
        outputFormat = 'html'
        outputDirectory = "$buildDir/documentation"
    }

    dataBinding {
        enabled = true
    }

    signingConfigs {
        platform {
            storeFile file("../certs/platform.keystore")
            storePassword 'xxxxxxxx'
            keyAlias 'platform'
            keyPassword 'xxxxxxxx'
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.platform
            zipAlignEnabled true
        }
        debug {
            debuggable true
            signingConfig signingConfigs.platform
            zipAlignEnabled true
            testCoverageEnabled = true
        }
    }

    androidExtensions {
        experimental = true
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation project(':library')
    implementation 'com.android.support:design:28.0.0'
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.21'
    implementation 'com.google.dagger:dagger:2.21'
    implementation 'com.google.dagger:dagger-android:2.21'
    implementation 'com.google.dagger:dagger-android-support:2.21'
    kapt 'com.google.dagger:dagger-compiler:2.21'
    kapt 'com.google.dagger:dagger-android-processor:2.21'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1-alpha3'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    implementation 'com.android.support.test:rules:1.0.2'
    implementation 'com.google.code.findbugs:jsr305:2.0.1'

library gradle :

    apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "kotlin-allopen"
apply from: '../buildsystem/android_commons.gradle'

allOpen {
    annotation 'com.xx.xxxx.xxxx.xxxxx'
}
android {

    defaultConfig {
        versionName "1.0"
        buildConfigField "String", "xx", "\"xx\""
    }

    androidExtensions {
        experimental = true
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.dagger:dagger:2.21'
    implementation 'com.google.dagger:dagger-android:2.21'
    implementation 'com.google.dagger:dagger-android-support:2.21'
    kapt 'com.google.dagger:dagger-compiler:2.21'
    kapt 'com.google.dagger:dagger-android-processor:2.21'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.21'
    implementation 'com.google.guava:guava:23.3-android'

}

repositories {
    mavenCentral()
}

Error:- Task :library:kaptReleaseKotlin FAILED error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass()

Vergeboard answered 28/2, 2019 at 6:43 Comment(8)
Can you please add your full error message?Anoint
Task :library:kaptReleaseKotlin FAILED error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass()Vergeboard
Add the additional flag to the build.gradle file to enable error type inferring in stubs: kapt { correctErrorTypes = true }Anoint
Check this link. Read Non Existent Type Correction.Anoint
Anything new after adding that kapt line?Anoint
error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass(). I need help unable to solve this error even after trying every solution. I'm stucked.Pulsatory
Narrow it down to which code is failing, you can delete some code, run it again, if it fails, delete more. Eventually you'll arrive at an annotated code element that fails. It should give you (and us) more clue on what is going wrong.Deloisedelong
If you using kapt you don't need to use annotationProcessor, error is generated by dagger-compiler or dagger-android-support but there is not enough info here to helpJunk
A
-1

To help you troubleshoot the issue with generating Doka docs for your project, I need to see the relevant Gradle files and error messages you're encountering. However, I can provide a general approach to debugging such issues, especially if they might be related to Dagger or any other dependency management.

General Steps to Troubleshoot Gradle and Dependency Issues

  1. Check the Error Message:

    • Carefully read the error message. Look for specific keywords, file names, line numbers, and other clues that can help you pinpoint the source of the issue.
  2. Verify Dependencies:

    • Ensure all necessary dependencies are correctly declared in your build.gradle files. Specifically, check for any Dagger-related dependencies.
    • Ensure there are no version conflicts between different dependencies.
  3. Clean and Rebuild the Project:

    • Sometimes, stale build artifacts can cause issues. Use the following commands to clean and rebuild your project:
      ./gradlew clean
      ./gradlew build
      
  4. Check Dagger Configuration:

    • Make sure that Dagger is correctly configured in your project. Verify that you have the correct @Module and @Component annotations and that they are properly linked.
    • Ensure that Dagger annotations are being processed correctly by including the Dagger annotation processor in your Gradle configuration.
  5. Update Dependencies:

    • Sometimes, the issue can be due to bugs in the dependencies themselves. Make sure you are using the latest stable versions of your dependencies.
  6. Consult Documentation and Forums:

    • Look for similar issues in the Dagger documentation, Stack Overflow, and other developer forums. Sometimes others might have faced the same issue and found a solution.

Example Gradle Configuration for Dagger

Here is an example of how your build.gradle file should look for a project using Dagger:

plugins {
    id 'java'
    id 'kotlin-kapt' // If you are using Kotlin
}

dependencies {
    implementation 'com.google.dagger:dagger:2.x'
    kapt 'com.google.dagger:dagger-compiler:2.x' // Use annotationProcessor if using Java

    // Other dependencies
}

kapt {
    correctErrorTypes = true
}

Posting Your Gradle Files and Error Messages

Please provide the following information to get more specific help:

  1. build.gradle Files:

    • The content of your project's root build.gradle file.
    • The content of your module-specific build.gradle file(s).
  2. Error Message:

    • The exact error message or stack trace you are receiving while generating the Doka docs.
  3. Dagger Configuration:

    • Any relevant Dagger configuration, such as @Module and @Component definitions.

With this information, I can offer more targeted advice on resolving the issue.

Araucaria answered 19/7 at 9:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.