Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:cannot access NotNull

I encounter the error above when compiling, and it doesn't goes to to any source file. After slowly identify the changes that cause the issue, found out it is apparently the dagger 2 inject is causing issue.

@FragmentScope
@Subcomponent
public interface MyComponent {
    void inject(MyJavaFragment myJavaFragment);

    void inject(MyJavaClass myJavaClass);

    void inject(MyKotlinClass myKotlinClass); // <- if change to Java, all works
}

I converted MyKotlinClass from Java code to Kotlin, and the error happens. This is in a library, and I already use that in build.gradle

kapt "com.google.dagger:dagger-compiler:$daggerVersion"

Why? (note: the app code is originally Java, so I didn't change all to Kotlin yet unless needed).

like image 395
Elye Avatar asked Feb 03 '26 22:02

Elye


1 Answers

After long hours of investigation, found out that, the calling Feature to this library, still using the Java Annotation

annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

But my library is using kapt as mentioned in the question above. So that's a clash of annotation processor used, and Java annotation processor is used instead I suspect. By changing the calling library annotation processor to

kapt "com.google.dagger:dagger-compiler:$daggerVersion"

would solve the problem. (remember to add apply plugin: 'kotlin-kapt' at the top as well)

like image 199
Elye Avatar answered Feb 05 '26 10:02

Elye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!