No Dagger2 generated files for JUnit tests

A new AndroidStudio 1.1 version introduced the unit testing support. This URL http://tools.android.com/tech-docs/unit-testing-support provides step-by-step instruction how to setup IDE to run JUnit tests for Android sources.

This plugin https://bitbucket.org/hvisser/android-apt used to provide Dagger2 generated files to AS and it works OK for usual Android code but unfortunately there is no generated Dagger2 files for any JUnit test class. I tried to configure dependency like

androidTestApt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'

according to android-apt plugin documentation but without success.

I think the problem is in different sources directory for Unit tests - it's src/test/java instead of src/androidTest/java that used by android instrumentation tests.

Can you please provide any help or info how to resolve this trouble?


Having

// You version may vary
androidTestApt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT' 

in your dependencies, open a terminal in your project, run

./gradlew assembleTest

This will generate the Dagger component classes living under your androidTest source set.

Go back to Android Studio, the class now exists and can be used.

链接地址: http://www.djcxy.com/p/83882.html

上一篇: 如何将时间范围绘制为来自Pandas或MatPlotLib的值

下一篇: 没有Dagger2为JUnit测试生成文件