Dagger 2 generated test component not recognized

后端 未结 3 1594
眼角桃花
眼角桃花 2020-12-09 19:37

I\'m hoping that this is just something I\'m doing wrong here. I\'m trying to use Dagger 2.0 to inject dependencies for my JUnit tests (not Espresso tests, just pu

3条回答
  •  星月不相逢
    2020-12-09 20:12

    Add this to build.gradle after android DSL:

    android {
        ...
    }
    
    android.applicationVariants.all {
        def aptOutputDir = new File(buildDir, "generated/source/apt/${it.unitTestVariant.dirName}")
        it.unitTestVariant.addJavaSourceFoldersToModel(aptOutputDir)
    }
    

    Thereafter, your test component would be recognized.

    For Kotlin replace generated/source/apt/... with generated/source/kapt/...

    There is an issue raised in the tracker concerning this.

提交回复
热议问题