Use dagger generated test code in Android

I am trying to use Dagger2 in my Android project as described in hitherejoe / Android-Boilerplate . While I am setting up the project, I got the following error during build.

Error:(30, 26) error: cannot find symbol variable DaggerTestComponent

After processing the documentation and the generated code, I realized that the code is not generated in the debug folder (/ app / build / generated / source / apt / debug /), but in test / debug (/ app / build / generated / source / apt / test / debug). Therefore, in my test source folder, the created DaggerTestComponent cannot be imported.

Any clue how to include a test / debug folder in the source code? My dependencies are as follows:

testCompile 'com.neenbedankt.gradle.plugins:android-apt:1.8'
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
testApt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"

Thanks in advance.

+4
2

... , :

android {
    sourceSets {
        // add dagger generated files (works only with debug build)
        test.java.srcDirs += ['build/generated/source/apt/test/debug']
    }
}
+5

:

// Dagger 2
provided "javax.inject:javax.inject:1"
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
-1

Source: https://habr.com/ru/post/1665523/


All Articles