Dagger "cannot access SomeComponent" during build

Viewed 494

I started a new project using Dagger 2. The module structure is as following (→ meaning depends on with implement):

app → data → network

Each module has it's own Dagger component (e.g. AppComponent, DataComponent and NetworkComponent).

@Component(modules=[...])
interface NetworkComponent

@Component(dependencies=[NetworkComponent::class], modules=[...])
interface DataComponent

@Component(dependencies=[DataComponent::class], modules=[...])
interface AppComponent

The idea behind this setup is that the app module has no access to network but only knows data. The real structure is more complicated but this is the main principle.

While Android Studio is very happy with this setup, gradle won't compile it.

The error is:

> Task :app:kaptReleaseKotlin FAILED
error: cannot access NetworkComponent
  class file for com.somepackage.network.di.NetworkComponent not found

* What went wrong:
Execution failed for task ':app:kaptReleaseKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

So while compiling the app module it fails to resolve the class it has no access to, but this class is nowhere referenced in the source of the app module. Dagger seems to internally trying to access it.

If I add a depency app → network the app compiles and runs fine.

Any idea how to solve this WHILE keeping app from accessing network? This separation is quite important for us.

0 Answers
Related