0

I am writing an Android app and created a Java file with an annotation that I am using in Kotlin classes. I am using kapt annotation processor.

Everything seems to show no errors in the compiler, but when I run the app, I get an error: incompatible types: NonExistentClass cannot be converted to Annotation - @error.NonExistentClass()

Is this just a kapt limitation? I read something about how Kotlin stubs out functions (but I think keeps declaration site). So that might mean it doesn't know what to do since the parameter in function declaration is marked with the annotation?

See: kapt replaces generated class references with error.NonExistentClass despite kapt.correctErrorTypes being enabled Any ideas how to resolve this?

Java Annotation File:

@IntDef(value = {Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC})
@Retention(RetentionPolicy.SOURCE)
public @interface MyTypefaceAnnotation { }

Kotlin Usage File:

sealed class MySealedClass(
    @StringRes val text: Int,
    @MyTypefaceAnnotation val typeface: Int,
    @ColorRes val fontColor: Int,
    val isEnrollmentButtonEnabled: Boolean
) {
    object NotSelected :
         MySealedClass (
            R.string.please_select,
            Typeface.NORMAL,
            R.color.light_grey,
            false
        )

// etc

Jeff Padgett
  • 2,380
  • 22
  • 34
  • Is the Java Annotation File really a .java File? Looks like Kotlin, so maybe it needs a extension change to ".kt"? Maybe you also need "@Target(ElementType.FIELD)" or similar for the Annotation class. – Demonick Apr 05 '21 at 07:40
  • It is Java, yes. How does it look like kotlin to you? Notice the `public` and `@interface`, instead of `annotation class`. Tried different @Target() types, including ElementType.FIELD) but same error. – Jeff Padgett Apr 06 '21 at 16:50

0 Answers0