Skip to content

Releases: google/dagger

Dagger 2.35.1

28 Apr 00:33
Compare
Choose a tag to compare

Hilt bug fixes

Dagger 2.35

23 Apr 00:46
Compare
Choose a tag to compare

What’s New in Hilt

Hilt is now stable!

This means that Hilt is ready for use in production. Thanks for all the feedback through our alpha and beta stages! From now on, Hilt will no longer have alpha/beta releases and instead will be released with the same process as Dagger.

New breaking changes

  • In the rare case that an app is relying on an @EarlyEntryPoint usage in a library that is built using an older version of Hilt, the @EarlyEntryPoint will no longer be picked up, resulting in a runtime error in tests (production code will be unaffected). To fix, all upstream usages of @EarlyEntryPoint must be built using this version of Hilt or later. (27a2827)
  • Hilt now checks that builds with @HiltAndroidApp do not depend on targets with @HiltAndroidTest and vice versa as this can cause confusion with which modules are included in which Dagger components. Hilt version 2.35.1 adds a flag to disable this check.

Bug fixes

  • Fix an issue where internal Kotlin object modules were incorrectly depended on directly by the component, which could result in a build failure if the component did not have visibility to the module. (115eaac)
  • Fix an issue in the Hilt Gradle Plugin where determining AGP version failed if the AGP version being used was older than 3.6. (0218653)

Dagger 2.34.1

13 Apr 20:41
Compare
Choose a tag to compare

Hilt Bug fixes

  • Fix #2070: Fix leak in FragmentContextWrapper by also releasing the inflators, if they exists. (41c4e04)

Dagger 2.34

07 Apr 21:52
Compare
Choose a tag to compare

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, 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.

  1. Add @HiltViewModel annotation to the class
  2. Replace the @ViewModelInject annotation on the constructor with @Inject.
  3. Remove @Assisted from the SavedStateHandle constructor parameter, if it exists
  4. Remove the old androidx.hilt:hilt-lifecycle-viewmodel dependency from your build.gradle file

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 disableAndroidSuperclassValidation when no Android entry points are in the source module. (c70cf2d)
  • Fix #2070: Clears the Fragment reference in FragmentContextWrapper after Fragment#onDestroy() to prevent leaks if a non-Hilt View outlives the Hilt Fragment that created it. (7f4c3a2)

Dagger 2.33

25 Feb 22:26
Compare
Choose a tag to compare

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 @Beta here means that this API is not considered stable -- the opposite from how the term is used in the Hilt “beta” release).
  • Fix an issue where Hilt's Gradle plugin was incompatible with Configuration Caching when enableExperimentalClasspathAggregation was turned ON. (b25eab8)
  • Fix issue with @DefineComponent classes with same name (785838e)

Dagger 2.32

08 Feb 22:39
Compare
Choose a tag to compare

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 on HiltAndroidRule 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 that inject() 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

  • Fix #2306: Fix an issue where internal Kotlin classes where not accessible with enableExperimentalClasspathAggregation turned ON. (53ceb91, 98c73c6)
  • Fix an issue where an @InstallIn module referencing a component without a component builder would fail (132d9ea)

Dagger 2.31.2

21 Jan 23:29
Compare
Choose a tag to compare

Bug fixes

  • Issue #2300: Reverts an unintentional change to Hilt and dagger-android-support that depended on RC versions of AndroidX (850274b)
  • Issue #2291: Reverts Hilt internal entry points back to public to avoid triggering an existing r8 optimization bug. (7a3d6fb)

Dagger 2.31.1

20 Jan 00:43
Compare
Choose a tag to compare

Bug fixes

  • Adds back the deprecated ApplicationComponent since the latest androidx.hilt:hilt-work release still uses it. (b9325a4)
  • Generated assisted factory classes are now final (6c11a60)
  • @AssistedInject types can now be used as @Assisted parameters (c4d829d)

Dagger 2.31

15 Jan 01:02
Compare
Choose a tag to compare

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

24 Nov 00:48
Compare
Choose a tag to compare

Bug fixes

  • Sets the default value for experimentalDaggerErrorMessages back to disabled 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)