Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

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

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 dependencies to app/build.gradle per the install instructions:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'

in writing my test, auto complete recognizes the existence of the artifacts. But when I run I get this error:

error: package android.support.test does not exist
error: package org.junit does not exist

and a number of other subpackages to these two.

So I removed the two above lines from build.gradle and attempted to add then in the GUI project structure/modules/dependencies

neither 'com.android.support.test.espresso:espresso-core:2.0' nor 'com.android.support.test:testing-support-lib:0.1' appear as options to choose from. However, in my file system there is <sdk>extrasandroidm2repositorycomandroidsupportestespressoespresso-core2.0 with the full complement of files including espresso-core-2.0.aar which I am able to open and navigate within it via winzip. In the file system it looks no different than the other libraries installed via SDK Manager with Support Repository.

Why doesn't android studio recognize this library?

Your help is greatly appreciated, no one else that I can find seems to have run into this problem. This is the closest I could find: Why do packages from library module does not exist upon compilation, even when Android Studio shows no errors in code?

I have tried reinstalling Support Repository twice.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same issue and I found that the dependencies with the androidTestCompile are visible only by default in the debug build variant.

You can change the build variant to be tested by adding this to your build.gradle:

android {
    ...
    testBuildType "staging"
}

where "staging" is just an example, you should replace it with one of your build variant.

Remember that only one variant is tested.

More information here https://code.google.com/p/android/issues/detail?id=98326


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...