I've tried implementing Jake Wharton's AssistedInject with Dagger 2 (https://github.com/square/AssistedInject) in my project.
My code is pretty much identical to https://github.com/square/AssistedInject/tree/master/inflation-inject-sample/src/main/java/com/example but I get the error:
error: cannot find symbol @dagger.Module(includes = {InflationInject_ViewModule.class})
It seems like ViewModule generated code doesn't know where to find InflationInject_ViewModule:
@InflationModule
@Module(includes = [InflationInject_ViewModule::class])
abstract class ViewModule
The relevant bits of my build.gradle are
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {...}
dependencies {
implementation "com.google.dagger:dagger-android:2.16"
implementation "com.google.dagger:dagger-android-support:2.16"
kapt "com.google.dagger:dagger-compiler:2.16"
kapt "com.google.dagger:dagger-android-processor:2.16"
implementation 'com.squareup.inject:inflation-inject:0.3.0'
kapt 'com.squareup.inject:inflation-inject-processor:0.3.0'
}
I have checked that InflationInject_ViewModule does exist in generated code (at build/generated/source/kapt/devDebug/com/project/di/, so maybe it's something to do with where the compiler looks for source sets / generated code.
Any suggestions?
I use AssistedInject, facing the same problem. In my case, turn out there is nothing wrong with my (or your) code, it's kapt problem.
If you use some library that requires kapt (e.g. room, databinding) those libraries may process before AssistedInject.
Something like: databinding -> room -> AssistedInject
If room compile fail, AssistedInject is never compile therefor InflationInject_ViewModule.java is not generated
Example error:
Conclution: check out other libraries in your project that require annotation processor. Make sure their setup was correct.