Releases: google/dagger
Dagger 2.32
What’s New
Dagger
- Parameters in
@AssistedFactory
classes that have the same type now require a name to be set via@Assisted("foo")
to disambiguate between arguments. Previously, order of parameters was used. Fixes #2281. (44d4f4b)
Bug fixes
- Fix #2359: Fixes self-loop when a generated implementation of an
@AssistedFactory
method calls a generated component method with the same name. (e2c9a9a) - Fix
@AssistedFactory
to allow for creating a parameterized Foo with type parameters specified by the factory. (552f430) - Issue #2279: Adds a better error message when trying to use a type parameter with an
@AssistedFactory
creator method. (9a90151) - Fix #2309: Fix a type inference issue with generated assisted factories in Java 7. (cda6e32)
Hilt
- A new
delayComponentReady()
method onHiltAndroidRule
allows deferring component initialization in tests until after test execution has started. This allows modifying@BindValue
field values in the case that default component initialization would have otherwise requested them before an@Before
or@Test
method. (315b1fa) HiltAndroidRule
now enforces thatinject()
is only called at most once per test case. (5dfd484)- Removes the deprecated
ApplicationComponent
. Note that this will now require upgrading any Androidx Hilt Worker dependencies to version 1.0.0-alpha03. (6592b06) - Fix #2337: Fix an incompatibility issue between the Hilt Gradle Plugin and AGP 4.2.0-beta04. Note that this fix makes it so that earlier versions of AGP 4.2.0 are incompatible with Hilt's Plugin. (9da5114)
Bug fixes
Dagger 2.31.2
Dagger 2.31.1
Dagger 2.31
What’s New
Dagger
Assisted Injection
Dagger now supports assisted injection. See the docs at https://dagger.dev/dev-guide/assisted-injection (daf0c66)
Hilt
@TestInstallIn
Adds a new @TestInstallIn feature to Hilt. This feature allows global test replacement modules to be defined instead of using @UninstallModules on individual tests. See the docs at (https://dagger.dev/hilt/testing#testinstallin) (d828472)
@HiltViewModel
Adds a new @HiltViewModel feature to Hilt. This replaces the @ViewModelInject AndroidX extension which will be deprecated in a future release.
@HiltViewModel differs from @ViewModelInject in that ViewModels are now injected from a ViewModelComponent with accompanying @ViewModelScope. See the docs for using @HiltViewModel at (https://dagger.dev/hilt/view-model) and docs on the ViewModelComponent at https://dagger.dev/hilt/components
(253ac8b)
Plugin local test support
When used with AGP 4.2.0+, the Hilt Gradle plugin will now transform local test classes by default. Usages of enableTransformForLocalTests
can be removed if using AGP 4.2.0+. See the docs at https://dagger.dev/hilt/gradle-setup#gradle-plugin-local-tests (d69b00f)
Experimental fix to classpath issues
An experimental flag enableExperimentalClasspathAggregation
has been introduced to the Hilt Gradle plugin to address issues where modules or entry points may be missed in multi-module Gradle projects when using implementation
dependencies. It is recommended to use this flag since without it, if an implementation
dependency hides a Hilt module/entry point, the resulting errors can be subtle and/or confusing and in the case of multibindings, may only manifest at runtime. However, there are also some build time tradeoffs to consider. See the docs at https://dagger.dev/hilt/gradle-setup#classpath-aggregation (239768b)
ApplicationComponent removed
The deprecated ApplicationComponent symbol has been removed. Users should migrate to SingletonComponent. This is intended to be a pure rename/functional no-op. (37cb8c8)
Dagger 2.30.1
Bug fixes
- Sets the default value for
experimentalDaggerErrorMessages
back todisabled
since it breaks hyperlinks in AndroidStudio (6a8bbbf) . Note that this reverses the change to the default value made in the release 2.30. - Fixes #2190: Dagger was unnecessarily inspecting all fields of a class and attempting to find their Kotlin metadata, which sometimes led to crashing the processor. Now, Dagger inspects the Kotlin metadata lazily, and only on the fields that require it. (a885c85)
Dagger 2.30
What’s new
Hilt
Hilt has deprecated ApplicationComponent
(6313cbd), and it will soon be removed in a future release. Use SingletonComponent
instead.
Hilt now supports @BindValue val
fields in Kotlin without the use of @JvmField
(802882d). For example:
// Before
@BindValue @JvmField val bindStr = "STRING_BINDING"
// Now
@BindValue val bindStr = "STRING_BINDING"
Dagger
Dagger now uses the “experimentalDaggerErrorMessages” by default (See #1769 for more information). The old error message format can still be used by setting -Adagger.experimentalDaggerErrorMessages=disabled
as a javacopt.
Bug Fixes
- [Dagger]: Fixes a Dagger compiler crash that occurred when an @Inject was placed in a Kotlin object class. (0816c43)
- [Hilt]: Fixes #2156: Update Dagger's androidx dependencies to the latest stable versions. (deff5e5)
- [Hilt]: Fixes suppress deprecation warning in Hilt generated Fragment class. (0a463eb)
- [Hilt]: Removes Hilt's dependency on jsr250 for
@Generated
. (8dca74b)
Note: Hilt previously depended on jsr250 for the@Generated
annotation, but this behavior has now been changed to match Dagger (see #95). Now, Hilt only adds the@Generated
annotation only if theGenerated
class is present in the classpath. Thus, since we’ve now removed the jsr250 dependency from Hilt, the generated code will no longer contain the@Generated
annotation by default.
Dagger 2.29.1
What’s New
Hilt
Hilt has two new artifacts hilt-core
and hilt-compiler
that allow Hilt to be used with pure Java/Kotlin libraries within an AndroidApplication (see issue #1908 for the full motivation/discussion).
The hilt-core
artifact contains the core (non-Android) Hilt APIs. Note that this artifact is only meant to be used by pure Java/Kotlin libraries within an Android application. Hilt does not currently support non-Android applications or non-Android tests.
The hilt-compiler
artifact is just a rename of hilt-android-compiler
. The motivation here is to have a single compiler artifact that works with both Android and non-Android libraries. The hilt-android-compiler
artifact will be deprecated in a future release, so please migrate to hilt-compiler
.
The example below shows which artifacts to use in an Android vs pure Java/Kotlin library.
// Android library deps
dependencies {
implementation "com.google.dagger:hilt-android:2.29-alpha"
androidTestImplementation "com.google.dagger:hilt-android-testing:2.29-alpha"
annotationProcessor "com.google.dagger:hilt-compiler:2.29-alpha" // or kapt
}
// Pure Java/Kotlin library deps
dependencies {
implementation "com.google.dagger:hilt-core:2.29-alpha"
annotationProcessor "com.google.dagger:hilt-compiler:2.29-alpha" // or kapt
}
Dagger:
A new Dagger compiler option was added to allow disabling transitive validation of component dependency, dagger.validateTransitiveComponentDependencies
,. The default value for the flag is enabled (same as before). To disable it, add the following to your compiler options: -Adagger.validateTransitiveComponentDependencies=DISABLED
. For a full motivation/discussion, see issue #970.
A new Dagger compiler option was added to fix an issue with map binding contributions that depend on subcomponent bindings, dagger.strictMultibindingValidation
. The default value for the flag is disabled (same as before). However, we will be enabling this flag in a future release. To check if your application will be affected, you can enable the flag by adding the following to your compiler options: -Adagger.strictMultibindingValidation=ENABLED
. See #2085 for details.
Potential breaking changes
- Fix an issue where in some cases missing bindings may have been missed during validation. This issue also affects the binding graph that SPI plugins receive so this fix may cause changes where a previously incorrect binding graph was being supplied. (08193ad)
Bug Fixes
- Fix #1955, #2065: Hilt would incorrectly try to transform native methods on classes annotated with
@AndroidEntryPoint
. (2099bad, 2099bad) - Fix #1918: Support
BroadcastReceiver
with@AndroidEntryPoint
transform. (ede018b) - Fix #1997: Allow Hilt modules to have constructors with params as long as a no-arg constructor exists. (07a7fa9)
- Fix #2042: Fix bug in
OriginatingElementProcessor
and ban@AndroidEntryPoint
classes with type parameters. (bee2e9a) - Fix #970: Add
-Adagger.validateTransitiveComponentDependencies
compiler option to prevent validating transitive component dependencies. (6deafc7) - Add
-Adagger.strictMultibindingValidation
compiler option to fix map binding contributions that depend on subcomponent bindings. (fb47e11) - Fix issue with
@Binds
when the impl extends a generated type. (71509b8) - Add support for receiving a callback for when the activity retained component will no longer be used and destroyed. (6300d02, 218df98)
- Throw when a race is detected adding a OnClearedListener. (7cf8b11)
- Reduce constant pool usage by renaming private methods (4a31157)
Dagger 2.29
Dagger 2.28.3
Dagger 2.28.2
What’s new
Hilt
The Hilt class dagger.hilt.android.components.ApplicationComponent
is being renamed to dagger.hilt.components.SingletonComponent
. This release adds the new SingletonComponent
class in preparation for this change without removing the existing ApplicationComponent
. This rename is part of a plan to address #1908 to allow usage of Hilt in non-Android Gradle modules when installing into the SingletonComponent
. Current users can begin switching to the new SingletonComponent
name as of this release. A future release will remove ApplicationComponent
.
Bug fixes
Hilt
- Fix #1980: Added missing FIELD target to @ActivityContext qualifier. (29e080f)
- Fix #1909: Update Dagger's JavaPoet dependency to 1.13.0 containing fixes for Dagger & Hilt related to generating code with overriding methods without annotations. (c5de4ab)
- Fix #1955: Fixes issue with bytecode transformation in Gradle plugin to allow @androidentrypoint annotations to be used with abstract classes containing abstract methods. (884fee5)
- Fix #1947: Fixes issue with Hilt base classes that extend other Hilt base classes. (61c5c43)
- Fix #1917: Fixes Hilt example app for Gradle users on mac. (5b3a966)