When I updated to Kotlin 1.3.70 I started getting this warning when building:
[WARN] Issue detected with dagger.internal.codegen.ComponentProcessor. Expected 1 originating source file when generating <path-to-repo>/app/build/generated/source/kapt/debug/com/example/feature/FeatureActivity_MembersInjector.java, but detected 0: [].
The FeatureActivity lives in another module which has kapt and dagger enabled but for some reason the injector is generated in the app module. Not sure what I can do to fix this issue.
MembersInjector only gets generated if Dagger has a component that will inject it.
Unless Dagger adds an option to always generate MembersInjector, you'll need to add a dummy component that declares that it can inject the FeatureActivity in your feature module. I think you can even make it a subcomponent to get around Dagger trying to verify the dependencies.
As a side note, kapt relies on these originating elements to be declared correctly for incremental processing to work, so not doing so will cause your kapt to become non-incremental.
When you say dummy component, you mean just create a component class with inject method for that activity, is that correct?
BTW, we also have same issue, we are using Dagger Android. Shouldn't dagger android processor create subcomponent with inject methods?
Can you add the com.google.dagger:dagger-compiler dependency to the module containing FeatureActivity. Once you've done that, Dagger will generated FeatureActivity_MembersInjector when compiling FeatureActivity.
The feature module already has the compiler as a dependency, but I believe the file isn't generated in that module because @ContributesAndroidInjector doesn't actually trigger the generation where applied but rather where the module is included.
When you say dummy component, you mean just create a component class with inject method for that activity, is that correct?
Yes.
@davidliu Why doesn't dagger android generator creates a subcomponent with inject method? Unused component class doesnt look like perfect option.
Keep in mind, I'm not a dagger contributor, only an avid user of it, so I don't know any of the context as to why this is, only that this is a workaround.
That said, doing a fresh project with just a member inject on a class, MembersInjector is generated just fine without any components or modules, so I'm unsure what the cause is.
I added dummy component for activity and fragments. Activity/fragment related warnings are gone. There is now DaggerApplication_MembersInjector.java missing warning. If I inline dagger application code to our application class, it is also get disappear, but I dont see benefit of inlining that class. Any suggestion to continue from here? I am also curious are we doing something wrong to have those warning or everyone else have same warnings?
Hmm, DaggerApplication_MembersInjector should already be included in the dagger-android artifact, and shouldn't need to be generated by the processor. Can you check if it's there? What version are you on?
And to be absolutely clear, when you say "missing warning", you mean the same warning as the OP of the thread?
DaggerApplication_MembersInjector is generated in app module but application class is in app. app module needs to create it. It is interesting that processor search for it in somewhere else.
About warnings, yes I had XActivity_MembersInjector.java, but detected 0: [] and added dummy components with inject method to force processor to create injector.
I think this is actually fixed in 2.27, can someone else confirm?
I also don't have member injector logs anymore with 2.27.
Closing. I believe this was fixed as part of https://github.com/google/dagger/commit/f83dce7bc80e8b055e32094e480b41f290f42d2e