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 ViewModel
s 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).
- 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
enableExperimentalClasspathAggregation
was turned ON. (b25eab8) - Fix issue with @DefineComponent classes with same name (785838e)