I have implemented dependency injection in android before using dagger 2 but, recently, I have tried to use it in a new project but I get the following error:
error: cannot find symbol import dagger.internal.InjectedFieldSignature; ^ symbol: class InjectedFieldSignature location: package dagger.internal/location/to/App_MembersInjector.java:30: error: cannot find symbol
Here is my Application component:
@Singleton
@Component(
modules = [
(AndroidInjectionModule::class),
(VmModule::class),
(InjectorModule::class),
]
)
interface ApplicationComponent: AndroidInjector<Application> {
@Component.Builder
interface Builder{
@BindsInstance
fun application(application: App): Builder
fun build() : ApplicationComponent
}
fun inject(home: Home)
}
Then in my App class:
class App: Application(), HasAndroidInjector {
@Inject
lateinit var anAndroidInjector: DispatchingAndroidInjector<Any>
override fun onCreate() {
super.onCreate()
DaggerApplicationComponent.builder().application(this).build().inject(this)
}
override fun androidInjector(): AndroidInjector<Any> {
return anAndroidInjector
}
}
Then the injector module:
@Module
abstract class InjectorModule {
@ContributesAndroidInjector
abstract fun bindHomeActivity(): Home
}
The following is a small excerpt of my app Gradle to show the dagger version:
implementation 'com.google.dagger:dagger-android:2.24'
implementation 'com.google.dagger:dagger-android-support:2.24'
kapt 'com.google.dagger:dagger-android-processor:2.24'
kapt 'com.google.dagger:dagger-compiler:2.28'
If you have any clue, kindly let me know where the problem might be.
Your Dagger artifact versions don't match. Specifically, you are using
dagger-compiler:2.28
to generate code, but including an dependency on Dagger 2.24 instead.In the specific case of
dagger.internal.InjectedFieldSignature
, that class appears to have been introduced in Dagger version 2.25.3. Any later version of the Dagger compiler will expect thatInjectedFieldSignature
exists and can be used in generated code. However, since you're only including Dagger 2.24 in your project, the generated code ends up referring to a class that doesn't exist.To fix this, make sure all of your Dagger dependencies use the same version.