1

假设我有

// 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
}

当我尝试执行上述操作时,我会收到一些与 Daggererror: cannot find symbol相关的错误。但是,当我@HiltAndroidApp从中删除时MyParentApplication,一切都编译得很好。显然,我不能这样做,因为 Dagger 注入在发布版本上不起作用。什么是适当的 Hilt 设置来注入派生/子类?

4

1 回答 1

1

刚生了两个孩子Applications。一为debug,一为release


  • 父级Applicationsrc/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
}
于 2020-08-13T20:06:34.527 回答