Repository navigation
Releases
Dagger 2.34
What’s New in Dagger
Bug fixes
- Fixed an issue where in rare cases subcomponent builder bindings might accidentally attach to the wrong parent (c2d097f)
- Build performance improvements (47123ec, 1caa7f0 8000 , e2f2b2d)
What’s New in Hilt
Hilt has a new flag, -Adagger.hilt.shareTestComponents, that enables tests with no test-specific bindings (e.g. @BindValue fields or @InstallIn modules within the test class) to share the same generated component. This flag should help improve build times by avoiding generating duplicate components for tests with the same bindings (faebc3c).
Note: This flag is currently disabled by default, but will be enabled by default in a future release of Hilt. For more information on how to enable this flag as well as some caveats, see the docs
New breaking changes
The alpha androidx extension @ViewModelInject is no longer supported. @ViewModelInject has been deprecated since androidx.hilt 1.0.0-alpha03 and was removed in androidx.hilt 1.0.0-beta01. Hilt now falls back to the base activity/fragment default ViewModelProviderFactory (3778ee2)
Migration steps:
Users of @ViewModelInject can migrate to @HiltViewModel which was added in Dagger 2.31.
- Add
@HiltViewModelannotation to the class - Replace the
@ViewModelInjectannotation on the constructor with@Inject. - Remove
@Assistedfrom theSavedStateHandleconstructor parameter, if it exists - Remove the old
androidx.hilt:hilt-lifecycle-viewmodeldependency from yourbuild.gradlefile
Bug fixes
- Update the androidx fragment, lifecycle and activity dependencies which contain patch fixes. (efcdbe1, 57255db)
- Fix #2511: updates the kotlinx-metadata dependency. (b42731b)
- Fix issue with proguard removing entry points by adding proguard keep rules. (96171b0)
- Fix #2456: Rename
init()method in generated Activity to avoid conflict with user method of same name. (1c66033) - Reduce the possibility of KAPT logging warnings due to no processor supporting
disableAndroidSuperclassValidationwhen no Android entry points are in the source module. (c70cf2d) - Fix #2070: Clears the
Fragmentreference inFragmentContextWrapperafterFragment#onDestroy()to prevent leaks if a non-Hilt View outlives the Hilt Fragment that created it. (7f4c3a2)
Dagger 2.33
What’s New in Dagger
Bug fixes
- Fixes #2370, #2396: Qualified @AssistedInject/@AssistedFactory types can now be provided and injected as normal bindings. (aff89b1)
What’s New in Hilt
Hilt is now in Beta!
Previously, Hilt has been in Alpha, and it is now officially in Beta. This means that there will be no further changes to the APIs until after Hilt becomes stable. We’ll focus on bug fixes and getting Hilt into a stable release.
(This also means that Hilt artifacts will now be postfixed with -beta instead of -alpha).
New breaking changes
Activity injection is now delayed until OnContextAvailableListener to enable member injecting ViewModels with SavedStateHandle. To use the ContextAware APIs androidx.activity, androidx.fragment and androidx.lifecycle dependencies are updated across the Dagger libraries. (623d3a6)
Note that this affects Hilt base classes that expected its members to be injected due to another Hilt class extending it. This essentially changes the injection of activities to occur within super.onCreate() instead of before super.onCreate().
@AndroidEntryPoint
public class MainActivity extends BaseActivity {
// ...
}
abstract class BaseActivity extends FragmentActivity {
@Inject Foo foo;
@Override
protected void onCreate(Bundle savedInstanceState) {
foo.doSomething(); // <- This will now result in an NPE since ‘foo’ hasn’t been injected yet.
super.onCreate();
}
}
For cases where a binding is strictly needed before super.onCreate() then the base class will have to invoke a Hilt generated method inject(). For example:
abstract class BaseActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
inject(); // <- This will force early injection.
foo.doSomething();
super.onCreate();
}
}
// An inject method to be overridden by the Hilt generated class.
protected void inject() {
throw new UnsupportedOperationException();
}
Bug fixes
- Allow entry points to be called in tests before the test instance is instantiated. This should help with issues like #2016 (For more details see https://dagger.dev/hilt/early-entry-point). (289f59f).
- Warning: This API is marked @Beta (Unfortunately, the naming here is confusing because
@Betahere means that this API is not considered stable -- the opposite from how the term is used in the Hilt “beta” release).
- Warning: This API is marked @Beta (Unfortunately, the naming here is confusing because
- Fix an issue where Hilt's Gradle plugin was incompatible with Configuration Caching when
enableExperimentalClasspathAggregationwas turned ON. (b25eab8) - Fix issue with @DefineComponent classes with same name (785838e)
Dagger 2.32
What’s New
Dagger
- Parameters in
@AssistedFactoryclasses 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
@AssistedFactorymethod calls a generated component method with the same name. (e2c9a9a) - Fix
@AssistedFactoryto 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
@AssistedFactorycreator method. (9a90151) - Fix #2309: Fix a type inference issue with generated assisted factories in Java 7. (cda6e32)
Hilt
- A new
delayComponentReady()method onHiltAndroidRuleallows deferring component initialization in tests until after test execution has started. This allows modifying@BindValuefield values in the case that default component initialization would have otherwise requested them before an@Beforeor@Testmethod. (315b1fa) HiltAndroidRulenow 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
experimentalDaggerErrorMessagesback todisabledsince 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@Generatedannotation, but this behavior has now been changed to match Dagger (see #95). Now, Hilt only adds the@Generatedannotation only if theGeneratedclass is present in the classpath. Thus, since we’ve now removed the jsr250 dependency from Hilt, the generated code will no longer contain the@Generatedannotation 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
BroadcastReceiverwith@AndroidEntryPointtransform. (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
OriginatingElementProcessorand ban@AndroidEntryPointclasses with type parameters. (bee2e9a) - Fix #970: Add
-Adagger.validateTransitiveComponentDependenciescompiler option to prevent validating transitive component dependencies. (6deafc7) - Add
-Adagger.strictMultibindingValidationcompiler option to fix map binding contributions that depend on subcomponent bindings. (fb47e11) - Fix issue with
@Bindswhen 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)