Dagger + Robolectric + Gradle + APT - source not generated for test module

(The question is available as a github repo here )

Edit: It looks like this is an issue with Android app not playing nicely with robolectric. 'gradle clean assembleDebugTest' will generate test sources, but 'gradle clean test' will not. I think android-apt

it will need to be changed to work in this case.

Edit 2: I solved my problem by temporarily changing the usage compile

instead of apt

, androidTestApt

or provided

. This question will remain open, although we should not include this material in our apkies.

I currently have a dependency on a project of mine that requires the Android APT plugin. Unfortunately, I can't get the test to pass when the APT plugin is applied.

Here's a quick overview of the project structure:

│   ├───MyTest
│   ├───TestModule
│   └───TestMyApplication [extends Application]


TestMyApplication overrides the method getModules()

in MyApplication and adds TestModule.

My dependencies section looks like this:

dependencies {
  compile 'com.squareup.dagger:dagger:1.2.2'
  apt 'com.squareup.dagger:dagger-compiler:1.2.2'
  androidTestApt 'com.squareup.dagger:dagger-compiler:1.2.2'
  androidTestCompile 'junit:junit:4.11'
  androidTestCompile 'org.robolectric:robolectric:2.3'


However, at runtime, I get the error:

java.lang.RuntimeException: java.lang.IllegalStateException: The module adapter for the com.example.myapplication.TestModule class could not be loaded. Make sure code generation has been started for this module.

If I disable android-apt

and use provides

instead of apt

and androidTestApt

, everything is fine!

Notably, it provides

doesn't work if a plugin is used android-apt


For the full source, please check out my repo here to illustrate this issue: https://github.com/jacobtabak/Robolectric-Dagger-Skeleton

There are 3 branches -

  • master

    which is my initial case that I want to work
  • provided

    which works using provided

    and disabled pluginandroid-apt

  • aptfail

    which is the same case as above, except that the plugin is applied android-apt

    , which fails.

Thank! For an answer to be accepted, it should NOT use "compile" for the dagger compiler.


source to share

All Articles