I am facing one issue using dagger2 + Kotlin This...
# android
I am facing one issue using dagger2 + Kotlin This is my ModuleClass
Copy code
object AppModule {

    fun provideRequestOptions() = RequestOptions.placeholderOf(R.drawable.white_background)

    fun provideGlideInstance(application: Application, requestOptions: RequestOptions) =

    fun provideAppDrawable(application: Application) =
            ContextCompat.getDrawable(application, R.drawable.logo)
In my Activity I am using 2 injects
Copy code
    lateinit var drawableLogo: Drawable

    lateinit var requestManager: RequestManager

    fun setLogo() = requestManager.load(drawableLogo).into(loginLogo)
I am getting below error:-
Copy code
/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 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
annotation used by the IDE but I am not sure about the exact issue, can somebody explain about this issue?
stackoverflow 2
⚠️ 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/.
You’re providing a drawable which is nullable ( ContextCompat.getDrawable returns Drawable? type ) but expecting a non-nullable injection in your field. Try to use non-nullable return type in module or mark your drawableLogo as nullable.
Tip: Always explicitly specify the return type of provides methods. Saves you a lot of unnecessary stress 😄
thx @Melih Aksoy, apparently I ran into another problem after changing
, as
can’t be used with nullable types.
Copy code
lateinit var drawableLogo: Drawable? = null
then I needed to change
to something like
but then it gave another error “Dagger doesn’t support injection into private fields. then finally I used something like
Copy code
internal var drawableLogo: Drawable? = null
but I don’t understand how this is working 😐