Android Testing Support Library not found with Espresso and different BuildVariants

Issue

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 'com.android.support:support-annotations:22.0.0'
    compile 'com.google.guava:guava:18.0'
    // Testing-only dependencies
    androidTestCompile 'com.android.support.test:runner:0.2'
    androidTestCompile 'com.android.support.test:rules:0.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
}

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?!

Edit:

I’ve created a AOSP-Ticket too: https://code.google.com/p/android/issues/detail?id172029

Solution

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

android {
  testBuildType "develop"
}

Answered By – MichaƂ Bendowski

Leave a Comment