https://kotlinlang.org logo
#dagger
Title
# dagger
v

vide

03/11/2024, 3:11 PM
What is going on here? I was cleaning up my
BaseApplication
and when I remove the last injection, I get this when compiling tests:
Copy code
Cannot process test roots and app roots in the same compilation unit:
  App root in this compilation unit: vide.BaseApplication
  Test roots in this compilation unit: [vide.Test1, vide.Test2, ...]
my classes look like this:
Copy code
// main
@HiltAndroidApp
class MainApplication : BaseApplication()
open class BaseApplication : BlahBlahApplication()
open class BlahBlahApplication : Application()
and
Copy code
// tests
open class TestApplicationBase : BaseApplication()

@CustomTestApplication(TestApplicationBase::class)
interface TestApplication
There's some base stuff in
BlahBlahApplication
that is overriden differently depending on if we're running in tests or not
If I add (for example) this to MainApplication, it compiles fine
Copy code
@HiltAndroidApp
class MainApplication : BaseApplication() {
    @Inject lateinit var app: Application
}
Why does hilt/dagger consider
BaseApplication
the application root if not injecting anything to
MainApplication
🤔
If anyone else happens to stumble into this issue, I cleaned up the inheritance to only inherit
Application
at the
MainApplication
level and Hilt is happy again. I would definitely want to understand what is going here though.
Copy code
// main
@HiltAndroidApp
class MainApplication : BaseApplication()
abstract class BaseApplication : Application(), BlahBlahApplication
interface BlahBlahApplication

// tests
open class TestApplicationBase : BaseApplication()

@CustomTestApplication(TestApplicationBase::class)
interface TestApplication
6 Views