Open pswaminathan opened 11 months ago
Have you inspected the KAPT generated stubs? It is likely the stub is missing the superclass.
This is likely occurring because correctErrorTypes
is turned off and KAPT will simply remove super-classes and super-interfaces instead of translating them to NonExistentClass
. Meanwhile turning the flag ON will make KAPT generate stubs with the not-yet-generated class, enabling processing to continue fine since that class will be generated by a Hilt processor.
There is some history about this flag being hardcoded off in the bazel rules: https://github.com/bazelbuild/rules_kotlin/issues/804 and https://github.com/bazelbuild/rules_kotlin/issues/634, I don't think there is anything on Hilt's side to do.
Wouldn't that result in it being NonExistentClass
, not Object
? The stubs show Object
.
KAPT doesn't always replace missing classes with error.NonExistentClass
, I don't know the details of why it doesn't for superclasses, maybe because it would generate a bad Java stub (is the missing type a class
or an interface
?), but the fact that the stub only contains Object
is an indicator that correctErrorTypes
is turned off and when using KAPT Dagger processes the Java stubs not the actual Kotlin sources.
A demonstration of this issue can be seen with:
More detail:
When using Dagger in a Kotlin project built with Bazel (really, anything without bytecode injection), AndroidEntryPoint processor processes, e.g.:
But instead of recognizing
Hilt_DemoApplication
as the superclass ofDemoApplication
, seesObject
. This causes the processor to fail with:This has not the same issue that bazelbuild/rules_kotlin#514 was opened with. That issue (annotation processor not being run) has been fixed. As you can see by this output, the annotation processor is being run. The code at issue is here. If you log out what superclass is being recognized, what you actually see is, e.g.
If you change that to use the generated class, it works. This is not a resolution, of course—it does not do the same thing as before of respecting the intended superclass + validating that it matches what is correct. But it demonstrates where the issue lies.