在父应用程序和子应用程序上使用@HiltAndroidApp
Using @HiltAndroidApp on Parent Application and Child Application
假设我有
// this class lives in the release (variant) directory
@HiltAndroidApp
open class MyParentApplication : Application() {
// some injection here
}
// this class lives in the debug (variant) directory
@HiltAndroidApp
class MyChildApplication : MyParentApplication {
// some debug only injection here. Debug injections won't be available as part of any app releases
// use debug only injections to do debug only actions
}
当我尝试执行上述操作时,我会遇到一些与 Dagger error: cannot find symbol
相关的错误。但是,当我从 MyParentApplication
中删除 @HiltAndroidApp
时,一切都可以正常编译。显然,我不能这样做,因为 Dagger 注入在发布版本上不起作用。获得 derived/child class 注入的适当 Hilt 设置是什么?
就两个childApplications
。一个用于 debug
,一个用于 release
。
- parent
Application
in src/main/your/package/
(无 @HiltAndroidApp
注释)
open class ParentApplication : Application() {
// some injection here
}
- 发布:
src/release/your/package/
@HiltAndroidApp
class ReleaseChildApplication : ParentApplication() {
// some injection can also be here, but does not have to...
}
- 调试: 在
src/debug/your/package/
@HiltAndroidApp
class DebugChildApplication : ParentApplication() {
// debug injections here
}
假设我有
// this class lives in the release (variant) directory
@HiltAndroidApp
open class MyParentApplication : Application() {
// some injection here
}
// this class lives in the debug (variant) directory
@HiltAndroidApp
class MyChildApplication : MyParentApplication {
// some debug only injection here. Debug injections won't be available as part of any app releases
// use debug only injections to do debug only actions
}
当我尝试执行上述操作时,我会遇到一些与 Dagger error: cannot find symbol
相关的错误。但是,当我从 MyParentApplication
中删除 @HiltAndroidApp
时,一切都可以正常编译。显然,我不能这样做,因为 Dagger 注入在发布版本上不起作用。获得 derived/child class 注入的适当 Hilt 设置是什么?
就两个childApplications
。一个用于 debug
,一个用于 release
。
- parent
Application
insrc/main/your/package/
(无@HiltAndroidApp
注释)
open class ParentApplication : Application() {
// some injection here
}
- 发布:
src/release/your/package/
@HiltAndroidApp
class ReleaseChildApplication : ParentApplication() {
// some injection can also be here, but does not have to...
}
- 调试: 在
src/debug/your/package/
@HiltAndroidApp
class DebugChildApplication : ParentApplication() {
// debug injections here
}