Skip to content

feat(hilt): Add limited dynamic feature module support for tests#5193

Open
Senthil455 wants to merge 1 commit into
google:masterfrom
Senthil455:dynamic-feature-support
Open

feat(hilt): Add limited dynamic feature module support for tests#5193
Senthil455 wants to merge 1 commit into
google:masterfrom
Senthil455:dynamic-feature-support

Conversation

@Senthil455

Copy link
Copy Markdown

When applying the Hilt plugin to a dynamic feature module (com.android.dynamic-feature), AGP provides a DynamicFeatureAndroidComponentsExtension which was not handled by the plugin's type checks, causing the error:

Failed to apply plugin 'com.google.dagger.hilt.android'.
Hilt plugin does not know how to configure 'extension 'androidComponents''

Changes

This change adds support for dynamic feature modules in a limited capacity by handling DynamicFeatureAndroidComponentsExtension in two key locations:

  1. Variants.kt (\onRootVariants) - Dynamic feature modules are treated like libraries: only test variants (unitTest and androidTest) are configured as Hilt roots where component trees are generated.

  2. HiltGradlePlugin.kt (\configureProcessorFlags) - Dynamic feature modules are assigned \GradleProjectType.LIBRARY\ since they cannot have a @HiltAndroidApp.

  3. GradleProjectType.java - Updated the Javadoc to reflect that dynamic features are now supported in a limited capacity.

Design Rationale

  • Dynamic feature modules cannot contribute bindings/modules to the main app's monolithic graph
  • They should be able to create test-specific graphs for writing unit tests and instrumentation tests
  • The library behavior is the right model: only test variants generate Hilt components
  • @HiltAndroidApp is still correctly rejected in dynamic features (enforced by AndroidEntryPointProcessingStep's GradleProjectType.APP check)
  • The bytecode transform (onAllVariants) still applies to all variants since @androidentrypoint classes may exist in tests

Fixes #5089

When applying the Hilt plugin to a dynamic feature module
(com.android.dynamic-feature), AGP provides a
DynamicFeatureAndroidComponentsExtension which was not handled by
the plugin's type checks, causing the error:
"Hilt plugin does not know how to configure 'extension androidComponents'"

This change adds support for dynamic feature modules in a limited capacity:
- Dynamic feature modules are treated like libraries for Hilt purposes
- Only test variants (unitTest and androidTest) are configured as Hilt roots,
  allowing test-specific graphs to be created
- Dynamic features cannot contribute bindings/modules to the main app graph
- @HiltAndroidApp is still correctly rejected in dynamic feature modules
  (enforced by AndroidEntryPointProcessingStep's GradleProjectType.APP check)

Fixes google#5089
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add limited dynamic feature support (for tests)

1 participant