为什么库模块 android.support.test 在添加依赖项中不可见 [英] Why is library module android.support.test not visible in add dependency

查看:48
本文介绍了为什么库模块 android.support.test 在添加依赖项中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Espresso 添加到我在 Android Studio 中的项目中.我已经安装了 Support Repository 并且实际上已经使用了它的一部分.然后我按照安装说明将这些依赖项添加到 app/build.gradle 中:

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.

所以我从 build.gradle 中删除了上面两行,然后尝试在 GUI 项目结构/模块/依赖项中添加

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

com.android.support.test.espresso:espresso-core:2.0"和com.android.support.test:testing-support-lib:0.1"都没有出现作为可供选择的选项.但是,在我的文件系统中有 <sdk>\extras\android\m2repository\com\android\support\test\espresso\espresso-core\2.0\ 和完整的文件,包括 espresso-core-2.0.aar 我可以通过 winzip 打开它并在其中导航.在文件系统中,它看起来与通过带有 Support Repository 的 SDK Manager 安装的其他库没有什么不同.

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>\extras\android\m2repository\com\android\support\test\espresso\espresso-core\2.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.

为什么android studio 不识别这个库?

Why doesn't android studio recognize this library?

非常感谢您的帮助,我找不到其他人似乎遇到了这个问题.这是我能找到的最接近的:为什么编译时库模块中的包不存在,即使 Android Studio 没有显示代码错误?

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?

我已尝试重新安装 Support Repository 两次.

I have tried reinstalling Support Repository twice.

推荐答案

我遇到了同样的问题,我发现 androidTestCompile 的依赖项仅在调试构建变体中默认可见.

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

您可以通过将其添加到您的 build.gradle 来更改要测试的构建变体:

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.

这里的更多信息https://code.google.com/p/android/issues/detail?id=98326

这篇关于为什么库模块 android.support.test 在添加依赖项中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆