I am trying to use the @ContributesAndroidInjector to provide a class in my dagger module and I'm seeing the error: [ClassName] is not a framework type.
Does anyone know what a "framework type" is and in which cases would a class not be one?
I am trying to use the @ContributesAndroidInjector to provide a class in my dagger module and I'm seeing the error: [ClassName] is not a framework type.
Does anyone know what a "framework type" is and in which cases would a class not be one?
In my case the error occurred when using dagger 2.20.
The issue drove me crazy so I took a clean example and everything was working correctly until I upgraded the version to 2.20. Then I got the "is not a framework type" error.
I changed the version to 2.19 and everything was working again.
If you have a look at the documentation it says that
This annotation must be applied to an abstract method in a Module that returns a concrete Android framework type (e.g. FooActivity, BarFragment, MyService, etc).
You can use it with fragments, activities, services, or applications. You can not use it to create arbitrary modules with arbitrary objects. You should use constructor injection where possible, and @Provides annotated methods where not.
Field injection is reserved for (Android) framework types and should not be used if you can provide your objects in the 2 ways mentioned above.
I would suggest that you have another look at the Dagger 2 documentation or some tutorials for further information on how you can provide objects. You can also find a blog post of myself about the Dagger Basics.
In my case, the error occurs when there is a compilation issue in the fragment and somehow dagger compiler runs first and things it's not a fragment (due to the compilation error).
If you have this issue after upgrading to version 2.20 like @aviv-mor, check you have also upgraded com.google.dagger:dagger-android-processor and com.google.dagger:dagger-compiler like that :
annotationProcessor 'com.google.dagger:dagger-android-processor:2.20'
annotationProcessor 'com.google.dagger:dagger-compiler:2.20'
Update the dependencies as given below:
// dagger
kapt 'com.google.dagger:dagger-compiler:2.20'
implementation 'com.google.dagger:dagger:2.20'
kapt 'com.google.dagger:dagger-android-processor:2.20'
implementation 'com.google.dagger:dagger-android-support:2.20'