无法解析符号“AndroidJUnit4" [英] Cannot resolve symbol 'AndroidJUnit4'

查看:44
本文介绍了无法解析符号“AndroidJUnit4"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然我需要正确的导入语句来解决这个问题.根据 AndroidJUnit4 文档,这应该是

Obviously I need the correct import statment to solve this problem. According to the docs for AndroidJUnit4, this should be

import android.support.test.runner.AndroidJUnit4;

当我这样做时,Android Studio 以红色突出显示 runner 并抱怨无法解析符号 'runner'".

When I do that, Android Studio highlights runner in red and complains "Cannot resolve symbol 'runner'".

背景

我通过遵循 Android 开发者网站上的 使用 UI Automator 设置测试.我遇到的第一个问题是 com.android.support:support-v4:22.2.0com.android.support.test:runner:0.2 依赖于不同的版本com.android.support:support-annotations.我遵循了此 Android 错误报告中的建议并将以下内容添加到我项目的 build.gradle 中的 allprojects:

I got to this point by following the tutorials on the Android Developer site for setting up tests using UI Automator. The first problem I encountered was that com.android.support:support-v4:22.2.0 and com.android.support.test:runner:0.2 depend on different versions of com.android.support:support-annotations. I followed the suggestions from this Android bug report and added the following to allprojects in my project's build.gradle:

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
}

这解决了直接错误,但我怀疑它会导致我当前的问题.有人对如何解决此问题有任何建议吗?

This solved the immediate error, but I suspect it lead to my current problems. Does anyone have any suggestions about how to fix this?

来自`./gradlew :app:dependencies的相关部分

androidTestCompile - Classpath for compiling the androidTest sources.
+--- com.jayway.android.robotium:robotium-solo:5.2.1
+--- com.squareup:fest-android:1.0.8
|    --- org.easytesting:fest-assert-core:2.0M10
|         --- org.easytesting:fest-util:1.2.5
+--- com.android.support.test:runner:0.2
|    +--- junit:junit-dep:4.10
|    |    --- org.hamcrest:hamcrest-core:1.1
|    +--- com.android.support.test:exposed-instrumentation-api-publish:0.2
|    --- com.android.support:support-annotations:22.0.0 -> 22.2.0
+--- com.android.support.test:rules:0.2
|    --- com.android.support.test:runner:0.2 (*)
--- com.android.support.test.uiautomator:uiautomator-v18:2.1.0

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:22.2.0
|    --- com.android.support:support-v4:22.2.0
|         --- com.android.support:support-annotations:22.2.0
+--- com.android.support:support-v4:22.2.0 (*)
+--- com.google.android.gms:play-services:6.1.71
|    --- com.android.support:support-v4:20.0.0 -> 22.2.0 (*)
+--- com.crashlytics.android:crashlytics:1.+ -> 1.1.13
--- com.jakewharton:butterknife:5.1.2

推荐答案

更新

Android 测试库现在是 AndroidX 的一部分.请务必使用官方文档.

The Android Test Library is now part of AndroidX. Be sure to use the correct Gradle dependencies found in the official documentation.

原答案

我发现这里有更新的版本测试支持库的比我使用的:

I found here that there are newer versions of the Testing Support Library than what I was using:

dependencies {
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}

注意:请务必使用这些库的最新版本.这个问题来自 Android 测试支持库是新的,这里的版本号非常过时.

Note: Be sure to use the most recent versions of these libraries. This question is from a time when the Android Test Support Library was new and the version numbers here are very out of date.

这篇关于无法解析符号“AndroidJUnit4"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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