Why is library module android.support.test not visible in add dependency

前端 未结 7 638
时光说笑
时光说笑 2020-12-14 08:01

I am adding Espresso to my project in Android Studio. I have installed the Support Repository and in fact have already been using pieces of it. Then I added these dependenci

7条回答
  •  暖寄归人
    2020-12-14 08:17

    I had this issue as well and I have my android test cases under src/androidTests as recommended by Google, but this caused problems with build.gradle:

    sourceSets {
        main {
            java.srcDirs = ['src']
        }
    }
    

    With the above it's trying to compile all my test cases within the normal debug compilation target, which does not include the espresso and other dependencies because they're listed under androidTestCompile.

    In the end I fixed this by excluding the androidTest subdirectory from compilation and set the root of androidTest to the appropriate directory.

    sourceSets {
        main {
            java.srcDirs = ['src']
            java.excludes = ['androidTest/**']
        }
        androidTest.setRoot('src/androidTest')
    }
    

提交回复
热议问题