Dagger2 is a powerful dependency injection library. However, it can be confusing for the first-time user. And unless things are created in the correct order, builds fail with cryptic error messages.
These step-by-step instructions were created while setting up a new project to document the process.
1. Setup Gradle version variables (optional)
2. Setup Gradle dependencies
3. Create an App class that extends Application
4. Add Timber logger initialization to App.onCreate() (optional)
5. Add App to manifest
6. Create any classes that will be injected by Dagger2
7. Create any classes that will @Inject objects using Dagger2
(use constructors but don't use @Inject yet)
8. Add UI implementation
9. Compile and run the code.
10. Create the following packages for Dagger2
* di.builder
* di.component
* di.module
11. Create AppModule.kt in di.module
12. Create activity module(s) in di.module for injecting singletons used by the activity
13. Create ActivityBuilder.kt in di.builder
14. Create any other builders as needed
15. Create AppComponent.kt in di.component
16. MainActivity now extends DaggerAppCompatActivity
17. Rebuild the app
18. App now extends DaggerApplication
19. Add required override for applicationInjector()
(verify DaggerAppComponent exists at this point)
20. Add any constructor or object injections using @Inject
21. Remove any hard coded method arguments of injected methods
22. Rebuild/run the app