Are your androidTestCompile dependencies mysteriously missing?

Being a responsible devloper (sic) I like to add unit and instrumentation tests when I add or change code. For reasons Mockito disappeared from my Android instrumentation tests this morning. My project is set up as a library module and an application module that uses the library. Read on to find out how to fix issues like this.

To cut a long story short, this happened when I changed the build variant of the application module to release, as shown below.

Build variant settings
Build variant settings

There are a lot of issues tagged with androidTest on Google’s tracker. They are aware of the issue and a fix will come but let’s work around it now.

I’m currently using:

  • Android studio 1.0
  • Android plugin 1.1.0
  • Gradle 2.2.1
  • Build tools 22.0.1

The first workaround is to set both build variants back to debug. The second one will allow you to use whatever build variant you like.  Open up the build.gradle and for each androidTestCompile line you have, add a provided scope for it. Change it from:

androidTestCompile 'org.mockito:mockito-core:1.10.19'

to:

provided 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'org.mockito:mockito-core:1.10.19'

Yes, I know it seems wrong but it at least it works!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s