-1
error: app.sareing.core.sharedPrefs.StringPreference cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
public abstract void inject(@org.jetbrains.annotations.NotNull()
                     ^
  app.sareing.core.sharedPrefs.StringPreference is injected at
      app.sareing.activity.MainActivity.authToken
  app.sareing.activity.MainActivity is injected at
      app.sareing.injection.component.ActivityComponent.inject(activity)

Tried Named fields, still no luck solving this.

Anurag Chutani
  • 591
  • 1
  • 4
  • 15

2 Answers2

0

In Dagger, you have two way to provide an object

  1. Using @Inject in the construction

Example:

UserRepository @Inject constructor(private val mContext: Context)

  1. But how can we @Inject constructor with some class of the third party like Retrofit Service Interface? That why Dagger has @Provide

Example:

@Module class AppModule { @Provides fun provideContext(application: Application): Context = application.applicationContext }

Dagger also has some other way to provide an object

You can read more here

In your case, you can provide your StringPreference class in your app module like AppModule

@Module class AppModule { @Provides fun provideStringPreference(context: Context): StringPreference = StringPreference(context) }

Khoa Tran
  • 528
  • 6
  • 18
0

Fixed by solution here https://stackoverflow.com/a/48057282/9821453

I was not using @fields:qualifier_name while injecting.

Thanks

Anurag Chutani
  • 591
  • 1
  • 4
  • 15