Dagger: NonExistentClass

Created on 10 Aug 2016  路  11Comments  路  Source: google/dagger

Sometimes the compiler don't know what wrong happens with the compile and return this blind error. I'm using Kotlin with the last stable version (1.0.3-release-IJ134-105). I feel a little bit lost when this error happens. I really don't know if it's problem with Dagger or Kotlin. Btw, can you help me?

screen shot 2016-08-10 at 11 15 37

(This error was triggered with a unknown error with the name of the class, strange...)

Most helpful comment

Some annotation processors (such as AutoFactory) rely on precise types in declaration signatures. By default, Kapt replaces every unknown type (including types for the generated classes) to NonExistentClass, but you can change this behavior. Add the additional flag to the build.gradle file to enable error type inferring in stubs:

kapt {
    correctErrorTypes = true
}

All 11 comments

What made you think of Dagger when you saw this? I don't see anything related to it in that error trace. Probably makes sense to post it to Jetbrains's or Gradle's issue trackers

This error happens with the Dagger's generated code, using kapt. If the code has some problem with the structure of the DI, the compiler gives me this error. It should be something more complete I think...

What happens when you try to manually build with ./gradlew clean?

I can reproduce such a message when I add an incorrect method in component's interface and try to Make a project

For example

fun inject(activity : MissingActivity) <<< Missing Activity

or

@Missing fun inject(activity: MainActivity) <<< Missing annotaion

In such cases I see a message in Gradle Console/Messages tab

error: cannot access NonExistentClass
class file for error.NonExistentClass not found
Consult the following stack trace for details.

I still don't see anything related to dagger... What if you remove dagger from kapt? Do you still get a similar error? what if you use another annotation processor, like @AutoValue but not dagger?

I think it is only kapt-related issue, not dagger-related.

For those who want to find the error in his/her own code:

  1. Comment the line kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  2. Run compile with --stacktrace --debug
  3. See real error in log.

You can also just run ./gradlew :app:compileDebugJavaWithJavac --stacktrace to find the source of the error

Some annotation processors (such as AutoFactory) rely on precise types in declaration signatures. By default, Kapt replaces every unknown type (including types for the generated classes) to NonExistentClass, but you can change this behavior. Add the additional flag to the build.gradle file to enable error type inferring in stubs:

kapt {
    correctErrorTypes = true
}

Source: https://kotlinlang.org/docs/reference/kapt.html#non-existent-type-correction

Was this page helpful?
0 / 5 - 0 ratings