Open emartynov opened 1 year ago
I see the StackOverflowException
in the debug log. Digging further.
Hi, @emartynov ! Right now I can't suggest anything but disabling Hilt's aggregating task
hilt {
enableAggregatingTask = false
}
Thank you for the suggestion! Let me check first what impact this flag will take on the project.
@sergei-lapin I set
hilt {
enableAggregatingTask = false
}
and it worked! But I'm not sure on the performance implications this may have since the tasks aren't isolating anymore. I'll be running some tests over the next week or so to see if the benefits of napt outweigh that cost.
I tried to apply the flag in all modules where we have the hilt plugin enabled. However, the project didn't build after.
It fails here: https://github.com/google/dagger/blob/master/java/dagger/internal/codegen/validation/DependencyRequestValidator.java#L82-L86
I plan to check the classpath for the dagger when napt is enabled.
@emartynov Have you removed all uses of kapt
from your other modules? I ran into a similar issue by mixing napt + kapt.
@sergei-lapin I am now running into a hilt issue where sometimes when I make a change and build I see
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacProcessingEnvMessager$Companion (file:/Users/zsweigart/.gradle/caches/modules-2/files-2.1/com.google.dagger/dagger-spi/2.44/4792c5cc751d0810dc93e9e53f2e42e6db15fefc/dagger-spi-2.44.jar) to field com.sun.tools.javac.code.Symbol.owner
WARNING: Please consider reporting this to the maintainers of dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacProcessingEnvMessager$Companion
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
An illegal reflective access operation has occurred
Illegal reflective access by dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacProcessingEnvMessager$Companion (file:/Users/zsweigart/.gradle/caches/modules-2/files-2.1/com.google.dagger/dagger-spi/2.44/4792c5cc751d0810dc93e9e53f2e42e6db15fefc/dagger-spi-2.44.jar) to field com.sun.tools.javac.code.Symbol.owner
Please consider reporting this to the maintainers of dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacProcessingEnvMessager$Companion
Use --illegal-access=warn to enable warnings of further illegal reflective access operations
All illegal access operations will be denied in a future release
error: [Hilt]
Attempt to recreate a file for type hilt_aggregated_deps._com_example_app_App_GeneratedInjector: javax.annotation.processing.FilerException: Attempt to recreate a file for type hilt_aggregated_deps._com_example_app_App_GeneratedInjector
But it's inconsistent and clean then build always works
Ok found the pattern:
ModuleA
depends on ModuleB
MyProfileActivity
in Module B ModuleB/build/generated/ap_generated_sources/internalDebug/out/hilt_aggregated_deps/_com_example_app_MyProfileActivity_GeneratedInjector.java
gets deleted and the build failsModuleB/build/generated/ap_generated_sources/internalDebug/out/
is cleared and re-generated; however, all hilt classes in ModuleA/build/generated/ap_generated_sources/internalDebug/out/com/example/app
are deletedModuleA/build/generated/ap_generated_sources/internalDebug/out
directory is deleted and regenerated and it worksBoth modules have
hilt {
enableAggregatingTask = false
}
As well as all other modules using the hilt and napt plugins.
I was able to reproduce this with the sample app in this repo once by creating a base module that has its own activity, hilt module, and simple object with an interface that is bound and injected into the activity.
In this app:
@Inject lateinit var someClass2: SomeClass
on line 11 of SecondaryActivity.kt
SampleBase
module, second time should fail in sample
module, third time should passAgain this has been flakey so sometimes I've had to clean before step 1 or even invalidate caches and restart.
It's a lot more consistent in my project which then becomes a developer experience nightmare
I gave 1.18 a try today on a new Android studio project and found a compilation issue:
* What went wrong:
Could not determine the dependencies of task ':app:mergeDebugJavaResource'.
> Could not create task ':app:hiltJavaCompileDebug'.
> Task with name 'hiltKotlinCompileDebug' not found in project ':app'.
Dependencies used:
Tested this without writing any Kotlin code (so no Hilt modules or Databinding layouts are present in the project).
@vibin that specific issue with task not found should be resolved with v1.19 release. The origin of this error is that you have aggregating task flag set true (default).
But Hilt is currently supported only with enableAggregatingTask = false
as mentioned above.
@sergei-lapin I was able to build a fairly large project with over 900 modules without disabling enableAggregatingTask. Can you explain why we need to disable it when using NAPT with Hilt? I'd prefer not to disable it for our project unless it's necessary.
Unable to read annotations on an injected Kotlin property. The Dagger compiler must also be applied to any project containing @Inject properties.
I got this error message above on my first attempt and discovered this GitHub issue. I tried disabling the aggregating task, but it didn't resolve the issue for me. Then I remembered that in Java classes, we can inject into fields by annotating the setter method. I replaced all field injections that were annotated with a Qualifier so that they now annotate the setter.
@ApplicationCoroutineScope
@Inject
lateinit var scope: CoroutineScope
to this:
@ApplicationCoroutineScope
@set:Inject
lateinit var scope: CoroutineScope
After replacing all the @Inject annotations that had qualifiers, it appears to be working. However, I'd like to ask: are there other reasons to disable enableAggregatingTask?
Hi! Thanks a lot for the plugin! This ticket is to make awareness and track progress about using this plugin with the Hilt dependency. If you don't want to have it, please close it.
We use hilt, and I applied the plugin application description to replace
kapt
withnapt
. However, the java compile task fails with the message:I've tried to add manually next dependencies to the app module:
However, it still fails. Drilling down to find the root case and possible solution.