Add @HiltWorker annotation processor support with @AssistedInject integration#5196
Open
Senthil455 wants to merge 1 commit into
Open
Add @HiltWorker annotation processor support with @AssistedInject integration#5196Senthil455 wants to merge 1 commit into
Senthil455 wants to merge 1 commit into
Conversation
…egration Add support for Hilt injection of WorkManager ListenableWorker classes via the @HiltWorker annotation. This enables Hilt to inject dependencies into WorkManager workers, including support for @AssistedInject constructors. Changes include: - @HiltWorker annotation to mark Worker classes for Hilt injection - HiltWorkerMap qualifier for internal multibinding map - HiltWorkerProcessor (Javac) and KspHiltWorkerProcessor (KSP) - HiltWorkerProcessingStep that processes @HiltWorker annotations - HiltWorkerMetadata validation (checks: extends ListenableWorker, has @Inject/@AssistedInject constructor, non-private, non-scoped) - HiltWorkerModuleGenerator generates: - _HiltModules class with @BINDS and @provides module bindings - _AssistedFactory interface (for @AssistedInject workers) annotated with @AssistedFactory so Dagger generates the factory implementation - HiltWorkerValidationPlugin prevents direct injection of @HiltWorker classes - Tests for @Inject and @AssistedInject worker scenarios Fixes google#4490
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4490
Add support for Hilt injection of WorkManager ListenableWorker classes via the @HiltWorker annotation. Previously, @AssistedInject constructors in @HiltWorker classes would fail with [Dagger/MissingBinding]\ errors after Kotlin/Gradle version updates.
Changes
New Annotations
New Processor Files
Modified Files
How It Works
For @HiltWorker with @Inject constructor:
The processor generates a module that binds the worker class into a multibinding map keyed by @LazyClassKey.
For @HiltWorker with @AssistedInject constructor:
The processor generates:
This ensures that non-@assisted parameters (like ReminderProcessor) are properly injected from the Dagger component, while @assisted parameters (Context, WorkerParameters) are passed in by WorkManager.