Android Testing Support Library not found with Espresso and different BuildVariants


We have three BuildVariants: release, debug and develop. The first are the defaults from AndroidStudio. The last is for our internal testing. Here are the configs: (There is nothing different than Signing Config) enter image description here enter image description here

We have imports the following in our build.gradle:

dependencies {
    // App dependencies
    compile ''
    compile ''
    // Testing-only dependencies
    androidTestCompile ''
    androidTestCompile ''
    androidTestCompile ''

Now we’ve created the androidTest/ folder (where the Espresso-Tests are located). I’ve looked at the example from the Android-Testing Samples in GitHub.

But AndoridStudio says always “Cannot find Symbole” for AndroidJUnit4.class: enter image description here

(And now, after a lot of explanation – sorry for that :D) I found the issue. Our Build Variants was set on Android Instrumented Tests (which is ok) but the App-Module was on the develop BuildVariant. When we have changed it to debug all was fine.

Now I’m not sure if this a bug or is this normal?! Because we have no different – instead of the Singing Config (but I’ve tested it, it isn’t the problem) – on the BuildVariants. And when it’s normal, why?!


I’ve created a AOSP-Ticket too:


Please see my update on the bug. In short, you need this line:

android {
  testBuildType "develop"

Answered By – MichaƂ Bendowski

Leave a Comment