paras
08/19/2019, 11:30 AMobject AppModule {
@JvmStatic
@Provides
fun provideRequestOptions() = RequestOptions.placeholderOf(R.drawable.white_background)
.error(R.drawable.white_background)
@JvmStatic
@Provides
fun provideGlideInstance(application: Application, requestOptions: RequestOptions) =
Glide.with(application).setDefaultRequestOptions(requestOptions)
@JvmStatic
@Provides
fun provideAppDrawable(application: Application) =
ContextCompat.getDrawable(application, R.drawable.logo)
}
In my Activity I am using 2 injects
@Inject
lateinit var drawableLogo: Drawable
@Inject
lateinit var requestManager: RequestManager
fun setLogo() = requestManager.load(drawableLogo).into(loginLogo)
I am getting below error:-
/app/build/tmp/kapt3/stubs/debug/com/example/di/AppComponent.java:7: error: [Dagger/Nullable] android.graphics.drawable.Drawable is not nullable, but is being provided by @org.jetbrains.annotations.Nullable @Provides android.graphics.drawable.Drawable com.example.di.AppModule.provideAppDrawable(android.app.Application)
public abstract interface AppComponent extends dagger.android.AndroidInjector<com.example.BaseApplication> {
^
android.graphics.drawable.Drawable is injected at
com.example.AuthActivity.drawableLogo
com.example.AuthActivity is injected at
dagger.android.AndroidInjector.inject(T) [com.example.di.AppComponent → com.example.di.ActivityBuildersModule_ContributeAuthActivity$app_debug.AuthActivitySubcomponent]
FAILURE: Build failed with an exception.
I think this issue is somehow related to @Nullable
annotation used by the IDE but I am not sure about the exact issue, can somebody explain about this issue?dawidhyzy
08/19/2019, 11:37 AM>>⚠️ Using Kotlin to build Android applications. :google: can answer many questions. Android Studio Integration. Android-specific Gradle. If not related to Kotlin, please consider using StackOverflow and/or http://android-united.community/.
Melih Aksoy
08/19/2019, 11:46 AMkingsley
08/19/2019, 11:58 AMparas
08/19/2019, 1:02 PMDrawble
to Drawable?
, as lateinit
can’t be used with nullable types.
@Inject
lateinit var drawableLogo: Drawable? = null
then I needed to change lateinit
to something like internal
but then it gave another error “Dagger doesn’t support injection into private fields.
then finally I used something like
@set:Inject
internal var drawableLogo: Drawable? = null
but I don’t understand how this is working 😐