Annotation Interface HiltAndroidApp
Application
class where the Dagger components
should be generated. Since all components will be built in the same compilation as the annotated
application, all modules and entry points that should be installed in the component need to be
transitive compilation dependencies of the annotated application.
Usage of this annotation is similar to AndroidEntryPoint
with the
only difference being that it only works on application classes and additionally triggers Dagger
component generation.
This annotation will generate a base class that the annotated class should extend, either
directly or via the Hilt Gradle Plugin. This base class will take care of injecting members into
the Android class as well as handling instantiating the proper Hilt components at the right point
in the lifecycle. The name of the base class will be "Hilt_ Example usage (with the Hilt Gradle Plugin):
Example usage (without the Hilt Gradle Plugin):
@HiltAndroidApp
public final class FooApplication extends Application {
@Inject Foo foo;
@Override
public void onCreate() {
super.onCreate(); // The foo field is injected in super.onCreate()
}
}
@HiltAndroidApp(Application.class)
public final class FooApplication extends Hilt_FooApplication {
@Inject Foo foo;
@Override
public void onCreate() {
super.onCreate(); // The foo field is injected in super.onCreate()
}
}
- See Also:
-
Optional Element Summary
-
Element Details
-
value
Class<?> valueThe base class for the generated Hilt application. When applying the Hilt Gradle Plugin this value is not necessary and will be inferred from the current superclass.- Default:
- java.lang.Void.class
-