I'm trying to create my app component, but Dagger does not generate my app component. here is MyApplication class
class MyApplication : Application() {
companion object {
@JvmStatic lateinit var graph: ApplicationComponent
}
@Inject
lateinit var locationManager : LocationManager
override fun onCreate() {
super.onCreate()
graph = DaggerApplicationComponent.builder().appModule(AppModule(this)).build()
graph.inject(this)
}
}
and here is my AppComponent class
@Singleton
@Component(modules = arrayOf(AppModule::class))
interface ApplicationComponent {
fun inject(application: MyApplication)
}
this is my project on github
here is error log
Error:(7, 48) Unresolved reference: DaggerApplicationComponent
Error:(28, 17) Unresolved reference: DaggerApplicationComponent
Error:Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
Information:BUILD FAILED
Information:Total time: 21.184 secs
Error:e: .../MyApplication.kt: (7, 48): Unresolved reference: DaggerApplicationComponent
e: Unresolved reference: DaggerApplicationComponent
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Information:4 errors
Information:0 warnings
Information:See complete output in console
In my case missing kapt compiler dependency. Please make sure to have below dependency too.
app build.gradle
This helped me to fix this issue
Add this in the top of the
build.gradle
Inside
android
tag addAnd then replace
to
Now
Rebuild
the project byPlease try enabling stubs generation, this might be the reason why the class is not visible at this stage of the build process. In your
build.gradle
file, top level:I've already downloaded your Github project. Thanks for sharing!
The answer for your issue is pretty simple:
Dagger dependencies files will be recreated and app after would launched with any problem.
I checked already this with Android Studio 2.1.2 version. It works
Please try adding this to your
build.gradle
EDIT: apparently a year later this can happen if you don't apply
kotlin-kapt
plugin. Also make sure you usekapt
instead ofannotationProcessor
.you should remove
and add to the top of application gradle file
then Dagger will take care of the rest :)