Skip to content

Releases: google/dagger

Dagger 2.39

30 Sep 01:06
Compare
Choose a tag to compare

What’s new in Hilt

New breaking changes

  • The compiler flag shareTestComponents now defaults to true. This may significantly improve test compilation time for large projects, but is a breaking change for some tests due to changed visibility requirements. See Hilt’s flags documentation for details. (7e09cee)
  • Hilt compiler flags are now strictly verified. Invalid flags will no longer compile. (742ba95)

Bug fixes

  • Fix #2779: Dagger no longer requires the additional google repository mentioned in the Dagger 2.28 release notes. (01cf47b)
  • There is now a runtime flag to control the Fragment.getContext() fix submitted in #2620. This allows enabling or disabling the fix without a compiler flag in order to permit a staged rollout. (c3f613f)
  • Fix #2789: Fixes issue with using EarlyEntryPoints being dropped when using enableAggregatingTask (38db196)
  • Fix a remote cache miss due to @Input parameter in ASM transform. (2f50035)

Dagger 2.38.1

27 Jul 20:07
Compare
Choose a tag to compare

Hilt bug fixes

  • Fix #2784. Fix an issue with AGP 7.0+ where the Gradle plugin bytecode transform was not applied to non-test code. This affected all @AndroidEntryPoint and @HiltAndroidApp classes that did not directly themselves extend from the Hilt-generated base class and meant that Hilt was not actually applied to those classes. (666df50)
  • Fix #2762. Fix an incompatibility with AGP 7.0.0-beta05 and 7.0.0-rc01 (09087db)

Dagger bug fixes

  • Fix #2765. Properly handle Kotlin metadata when shading dependencies. (ef7e7a1)

Dagger 2.38

20 Jul 01:02
Compare
Choose a tag to compare

What’s New in Dagger

New breaking changes

Add the Google Maven repository for KSP artifacts

As part of necessary changes in order to eventually support running Dagger as a KSP processor, Dagger now has a dependency on the KSP artifacts. These artifacts are available from the Google Maven repository, so this may break users who currently do not use this repository for other dependencies. The Google Maven repository is available at https://maven.google.com.

Adding the repository in Gradle

In your build.gradle file, add google() in repositories.

repositories {
  google()
}

Example: https://github.com/google/dagger/blob/ff62b195c1a00727192154a409aa4ab0b796ff07/javatests/artifacts/dagger/simple/build.gradle#L23

Adding the repository in Bazel

If using the repository list from our workspace_defs.bzl, then no change is needed.

Otherwise, pass "https://maven.google.com" to your usage of maven_install.

maven_install(
    repositories = [
      "https://maven.google.com",
      ...
    ],
    ...
)

Adding the repository in Maven

Add the repository in your pom.xml file like the following:

  <repositories>
    <repository>
      <id>google-maven</id>
      <name>Google Maven Repo</name>
      <url>https://maven.google.com</url>
    </repository>
  </repositories>

Example:
https://github.com/google/dagger/blob/ff62b195c1a00727192154a409aa4ab0b796ff07/examples/maven/pom.xml#L20

Bug Fixes

  • Fix #2576. Check and give a better error message when a user added method has a name that is a java reserved keyword. (436ac2e)
  • Fix #2575. Check and give a better error message when a user added method has the same method signature as generated factory methods. (6971d00)
  • Fix #2570. De-dupe assisted parameter names and field names to avoid a case where generated code may have naming conflicts. #2570 (3d93625)
  • Fix #2710. Allow Dagger-defined map keys (like ClassKey and StringKey) to be placed on fields in order to support Hilt's @BindValueIntoMap. (7af40df)
  • Errors for requesting bindings from the wrong component now include the component name for each binding along the dependency path for easier debugging. (2335e0f)

What’s New in Hilt

This release fixes an incompatibility in the Hilt Gradle Plugin with AGP 7.0-beta04 and 7.1-alpha03. However, with this fix the HiltGradlePlugin will not work with alpha/beta versions of AGP 7.0 and 7.1 older than the versions previously mentioned. This fixes #2700. (be2f89a)

Bug Fixes

  • Fix #2710. Allow Dagger-defined map keys (like ClassKey and StringKey) to be placed on fields in order to support Hilt's @BindValueIntoMap. (7af40df)
  • Fix #2695. Fix an issue where enableAggregatingTask would not correctly generate Hilt classes when compiling in a dev environment with Windows OS. (a7c3c9e)
  • Fix #2672. Fix cast errors when getApplicationContext() is overridden. (4b695ae)

Dagger 2.37

10 Jun 21:43
Compare
Choose a tag to compare

What’s New in Dagger

Bug Fixes

  • Fix #1079: Added an automatic module name to the com.google.dagger:dagger artifact to improve Java 9 compatibility. (cb30885)
  • Removed the com.google.dagger:dagger-android-jarimpl artifact. This was an internal-only artifact, so its removal should not affect users. (6da2e7e)

What’s New in Hilt

Build performance improvements for Gradle

There’s a new flag, enableAggregatingTask, supported by the Hilt Gradle plugin that allows Hilt to perform classpath aggregation in a dedicated Gradle task. This allows Hilt’s annotation processors to be “isolating” so that they are only invoked when necessary. This reduces incremental compilation times by reducing how often an incremental change causes a rebuild of the Dagger components. For details on how to enable this flag see https://dagger.dev/hilt/gradle-setup#aggregating-task.

Note that the default for enableAggregatingTask is currently false, but it will be changed to true in an upcoming release, so please try to enable this flag and report any issues.

Also, note that enableAggregatingTask will automatically enable sharing test components, so please read the caveats for enabling that flag as well.

Finally, enableAggregatingTask replaces enableExperimentalClasspathAggregation which will be removed in an upcoming release. Please replace any usages of enableExperimentalClasspathAggregation with enableAggregatingTask.

Bug Fixes

  • Fix #2662: Fixes an issue in Hilt's bytecode transform that would cause classes to fail validation if they contained an instantiation of an object whose type is the same as the superclass of the @androidentrypoint annotated class. (839a849)

Dagger 2.36

26 May 00:00
Compare
Choose a tag to compare

What’s New in Dagger

New breaking changes

  • Added compile time set binding validation for cases where the same binding key is bound into a set multiple times. Previously, cases of this could result in a runtime failure due to a similar check at runtime, but in rare cases that don’t trigger the runtime error, this could be a breaking change. (cf20470)

Bug Fixes

  • Make nested subcomponents and switching provider impls static within the generated component class. This is in preparation for eventually unnesting these classes from within their parent component to avoid issues that arise from deeply nested class names being too long. (d9f08aa)

What’s New in Hilt

Fragment#getContext() behavior fixed behind a flag

Currently, a Hilt fragment’s getContext() method incorrectly continues to return a context value even after the fragment is removed. This differs from the behavior of a regular fragment. Fixing this is a breaking change that may introduce crashes at runtime if code incorrectly accessed the fragment’s context after removal and relied on Hilt’s incorrect behavior, so a flag has been introduced with the new fixed behavior default off.

Please enable the flag with -Adagger.hilt.android.useFragmentGetContextFix=true to roll out this change at your own discretion. You may choose to, for example, start by enabling this only in development or some small testing population to find errors. In a future release, this flag will be defaulted to true and then in some release after that, the flag will be removed. (5ce0cea)

Bug Fixes

  • Fix a bug where a Hilt fragment’s getContext() method could not be called before super.onAttach(). (8acc433)
  • Fix compatibility issue with the Hilt Gradle Plugin and Android Gradle Plugin 7.0 (371a2c3)
  • Fix lint issue with Hilt testing classes that get compiled to reference invalid ReflectiveOperationException for API < 19. (e58abc3)

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)