@Retention(value=RUNTIME)
@Target(value=TYPE)
public @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()
}
}
AndroidEntryPoint
Modifier and Type | Optional Element and Description |
---|---|
java.lang.Class<?> |
value
The base class for the generated Hilt application.
|