使用@Qualifier 时,[Dagger/MissingBinding] int[] 不能在没有@Provides 注释的方法的情况下提供

When using @Qualifier, [Dagger/MissingBinding] int[] cannot be provided without an @Provides-annotated method

我已经编写了下面的代码来获取 IntArray,当我不使用 @Qualifer 对其进行注释时它工作正常,但是当我这样做时,我收到以下错误消息:

我的模块文件(注释和模块都在同一个文件中)

@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)
    }
}

dialogFragment 中的用法:

@Inject
@ItemColorArray
lateinit var itemColorArray: IntArray

错误信息:

{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

同样,当我不使用任何 @Qualifier 时一切正常。使用 @Named("xxx") 限定符会产生相同的错误。 提前致谢。

Dagger version 2.25.

修复/改进了字段上使用 Kotlin 的限定符

确保使用最新版本,它应该可以工作。


或者您可以使用 @field:MyQualifier 以便以前的版本可以使用它。