Generate code for unit test build in Android Studio

1.1k views Asked by At

When using android-apt plugin is it possible to generate code for the test build? Specifically I am using Dagger and have some TestModules that are only needed for unit test and want those in the test build only. Seems the plugin does not support testApt 'my-dependency'.

3

There are 3 answers

0
tomrozb On BEST ANSWER

It should be possible with gradle plugin 1.3. More information here.

You can try the beta plugin:

classpath 'com.android.tools.build:gradle:1.3.0-beta1'

If it doesn't work you have to wait for final version of the plugin. More information under the link provided above.

1
Rajesh Batth On

Use testApt

testApt "com.google.dagger:dagger-compiler:2.0"
0
Marius Constantin On

Add this to your build.gradle

testCompile 'com.google.dagger:dagger:2.0.1'  
testCompile 'com.google.dagger:dagger-compiler:2.0.1'

Even though the AndroidStudio will complain about the missing Dagger generated classes, your Unit Tests will compile and run without any problem. For the moment this is the only solution until the 'testApt' feature will be added into the new Gradle release.