Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

android - NonExistentClass cannot be converted to Annotation

I added a new Retrofit interface to my project containing a couple of Endpoints annotated with the @GET and @HEADERS annotations, after Injecting said interface to a repository class using the @Inject annotation in the constructor of said class, Android Studio throws this error:

NonExistentClass cannot be converted to Annotation

After taking a look at the generated Java code, it replaces the @GET and @HEADERS annotations with this:

@error.NonExistentClass()

I've already tried the following:

  • Using annotatioProcessor instead of kapt

  • Setting jetifier.enabled to false in gradle.properties

  • Setting generateStubs to true in my build.gradle file

  • Setting correctErrorTypes to true in my build.gradle file

Im using:

  • Android Studio 3.3

  • Kotlin 1.3.11

  • Dagger 2.21

  • Retrofit 2.3.0

  • Kotlin

  • Kapt

could it be some dagger scope issue? or Retrofit / dagger not fully compatible with the new versions of the Kapt plugin?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Luckily this question led me to figure out my issue. While moving around classes from an app module into a library, I was referencing an annotation class which only existed in a debug folder. So debug builds were fine, but calls to gradlew install failed when generating release files.

The error for me was very explicit although it took me a long time to realize - the generated file had literally replaced the missing annotation with @error.NonExistentClass()

Moving the file into the main src set meant both debug and release builds could see the class. What took me a while to figure out was that I assumed this was a Dagger issue being masked by kapt, but really it was just a regular old Dagger issue. My advice is to look at your Dagger setup carefully.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...