Android Studio 中测试支持库的来源 [英] sources of Testing Support Library in Android Studio

查看:46
本文介绍了Android Studio 中测试支持库的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 android.support.test.* 附加源以在 AS 中进行调试?
尝试从 https://android.googlesource.com/platform/frameworks/testing 下载源但版本似乎与我的测试库版本不匹配.

How to attach sources from android.support.test.* for debugging in AS?
Tried downloading sources from https://android.googlesource.com/platform/frameworks/testing but the version doesn't seem to match my testing library version.

测试源(例如 AndroidJunitRunner)似乎无法通过 sdk 管理器获得,我是否遗漏了什么?

Testing sources (for instance AndroidJunitRunner) don't seem to be available via sdk manager, am I missing something ?

推荐答案

我遇到了类似的问题,花了很长时间才弄明白.这似乎是一个错误,因为缺少 Gradle 任务没有执行,因为 SAME 配置曾经可以工作,但在升级到 AS v1.2+ 后不再有效.

I encountered a similar problem and it took a quite amount of time to figure it out. It seems like a bug due to a missing Gradle task not executed because the SAME configuration used to work but not any more after upgrading to AS v1.2+.

首先,以下依赖项已过时.

First, the following dependency is obsolete.

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

并且在文档中更新如下.

androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
...

defaultConfig 应该像往常一样包含以下行.

The defaultConfig should include the following line as usual.

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

另外,请确保通过 SDK 管理器安装了 Android Support Repository.

Also, make sure the Android Support Repository is installed through the SDK Manager.

如果android.support.test.*无法解析,则手动执行如下Gradle任务.

If android.support.test.* cannot be resolved, then manually execute the Gradle task as follows.

  1. 点击右侧的 Gradle 标签.
  2. 折叠您的 Android 模块并浏览任务节点.
  3. 双击执行other->generateDebugAndroidTestSources

如果成功,问题可能会得到解决.至少,它对我有用.

If succeeded, the issue may be solved. At least, it works for me.

更新:

在 AS 2.1.2 上似乎仍有可能发生这种情况.需要注意的是,如果你有多个 Android 模块,从一个特定的运行 gradle 任务 generateDebugAndroidTestSources 应该足够了,尤其是 Android 库模块一.

It seems like there are still chances this could happen on AS 2.1.2. To be noted, if you have more than one Android modules, running the gradle task generateDebugAndroidTestSources from one particular should be enough for all, especially the Android library module one.

这篇关于Android Studio 中测试支持库的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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