1

I am trying to create a stand alone library and use dagger 2 in it, I already create the module and the component of the library, and make the initialisation of the library including the dagger component, my goal here is I wanted this library can be used even the project who implemented it did not use dagger. but it seems my configuration only can work if the project implemented it, also use dagger2 cause I got error :

Application does not implement dagger.android.HasDispatchingActivityInjector

So are there anyway I can still dagger2 in my library without having the project who implemented it also use dagger2 ?

ps : My library contain an activity

mangkool
  • 316
  • 2
  • 18
  • Your library should provide a custom `Application` that extends `DaggerApplication`. However, it is not recommended to use Dagger in a library. – Joshua Jan 22 '19 at 06:38
  • thanks @Joshua , are there any reasons why it is not recommended to use dagger in library ? – mangkool Jan 22 '19 at 06:44
  • When you build a library, you should not require the application to use dependency inject framework because dependency inject framework is designed for application level. Instead, you should design your library to follow the principle. You can read more [here](https://stackoverflow.com/a/2047657/3673259). – Joshua Jan 22 '19 at 06:59
  • okayy, I see, thanks – mangkool Jan 22 '19 at 07:19

1 Answers1

-2

It was because of missing android:name key with the value of my Application subclass to my manifest file.

Eg: Add android:name=".MyApplication" in your manifest under application tag. Change the 'MyApplication' to the name of your application class