I've written the code below to get me an IntArray
and it works fine when I'm not annotating it with @Qualifer
, but when I do, I get the error message below:
My module file (both annotation and modules are in same file)
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
annotation class ItemColorArray
@Module
class ModuleGeneral {
@Provides
@ItemColorArray
fun provideItemColorArray(context: Context): IntArray {
return context.resources.getIntArray(R.array.timetableItems)
}
}
Usage inside a dialogFragment:
@Inject
@ItemColorArray
lateinit var itemColorArray: IntArray
Error message:
{fileAddress}\di\AppComponent.java:8: error: [Dagger/MissingBinding] int[] cannot be provided without an @Provides-annotated method.
public abstract interface AppComponent {
^
int[] is injected at
{packageName}.ui.dialogs.addSubject.AddSubjectDialog.itemColorArray
Again, everything works fine when I'm not using any @Qualifier
. Using the @Named("xxx")
qualifier produces the same error.
Thanks in advance.
Qualifiers with Kotlin on fields were fixed / improved with Dagger version 2.25.
Make sure to use the latest version and it should work.
Alternatively you can use @field:MyQualifier
so that previous versions can pick it up.