Seeing this frequently with incremental builds since updating to 2.25.2. Works fine on a clean build.
/path/to/AppComponent.java:78: error: [Dagger/MissingBinding] android.net.Uri cannot be provided without an @Provides-annotated method.
public interface AppComponent extends AndroidInjector<App>{
^
android.net.Uri is injected at
ynab.app.web.WebViewActivity.serverUrl
Here's the relevant parts of the component (Java):
public interface AppComponent extends AndroidInjector<App>{
// lots of other stuff
@Component.Builder
interface Builder {
// lots of other stuff
@BindsInstance Builder serverUrl(@Named("ServerUrl") Uri serverUrl);
}
}
The error only happens since updating Dagger to 2.25.2 and changing the injection site to benefit from the new Kotlin support.
@Inject @field:Named("ServerUrl") internal lateinit var serverUrl: Uri
@Inject @Named("ServerUrl") internal lateinit var serverUrl: Uri
If I have misunderstood what's supposed to be possible with 646e0336cdbe454baa5fe73c0af11f211a92deeb then I look forward to being educated. :)
Dagger 2.25.2
Kotlin 1.3.50
Android Gradle Plugin 3.5.1
Thanks for reporting this! We are aware of some cases where Dagger is still unable to find the qualifier annotation, meaning you have to fallback to @field:Named.
I was able to reproduce the issue in a small project with two gradle modules. App and Lib. Where Lib has the Kotlin class being member injected and App is where Dagger is setup with kapt. The issue is that Dagger is failing to find the synthetic method where property annotations are placed when the class being inspected is not from source, i.e. its already compiled.
We are still working on a fix but at the same time I filled a bug towards kapt with regards to the stub inconsistency: https://youtrack.jetbrains.com/issue/KT-34684
@danysantiago Thanks! In my case the Kotlin injection target is in the same gradle module as the Dagger setup.
Dagger is failing to find the synthetic method where property annotations are placed when the class being inspected is not from source, i.e. its already compiled.
Would this also apply in the case of incremental compilation in the same gradle module, i.e. if my Kotlin injection target class has already been compiled in a previous build?
Yes - It might be possible that this is also observed during incremental builds.
@GrahamBorland why not switching from @Namedto @Qualifier?
Example:
```
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class ServerDateFormat
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class CalendarPickerDateFormat
@Provides
@Singleton
@ServerDateFormat
fun provideServerDateFormat(): SimpleDateFormat {
return SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault())
}
@Provides
@Singleton
@CalendarPickerDateFormat
fun provideCalendarPickerDateFormat(): SimpleDateFormat {
return SimpleDateFormat("dd/MMM/yyyy", Locale.getDefault())
}
```
Not as a workaround but as an improvement.
@GuilhE This issue reproducible and for @Named and for @Qualifier, so no difference.
as an improvement
It's improvement only if you do not use this dependency between modules, sometimes you just cannot access annotation without creating a separate module for it which is overkill in many cases
@gildor thanks for sharing this knowledge, never had to use @Qualifiers between modules, only in the provider class and ViewModels/Classes.
I just noticed this where we are running kapt on a library -> app module style setup.
Most helpful comment
Thanks for reporting this! We are aware of some cases where Dagger is still unable to find the qualifier annotation, meaning you have to fallback to
@field:Named.I was able to reproduce the issue in a small project with two gradle modules. App and Lib. Where Lib has the Kotlin class being member injected and App is where Dagger is setup with
kapt. The issue is that Dagger is failing to find the synthetic method where property annotations are placed when the class being inspected is not from source, i.e. its already compiled.We are still working on a fix but at the same time I filled a bug towards
kaptwith regards to the stub inconsistency: https://youtrack.jetbrains.com/issue/KT-34684