【问题标题】:Android Studio doesn't import androidx testing classes properlyAndroid Studio 没有正确导入 androidx 测试类
【发布时间】:2019-05-05 14:33:34
【问题描述】:

我一直在研究 UIAutomator 示例项目。我已经使用 AndroidX 测试库创建了新的测试用例。

我能够从命令行构建、运行测试用例。但是当我尝试从 Android Studio 打开应用程序时,我可以看到大多数类都没有正确导入。例如,

import androidx.test.uiautomator.UiObject2;
import org.junit.Before;

以上两个导入显示为未导入。同样,除了 android.content.Context、android.content.Intent 等,许多类都显示相同的错误,

有人可以对此有所了解。我能够从命令行正确执行测试用例,但无法从 Android Studio 正确执行。

我已经重启了PC/Studio,清除了缓存,问题依然存在。

下面是我在 app/build.gradle 中添加的依赖。

androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test:core:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'junit:junit:4.12'

在 gradle.properties 中添加以下代码

android.useAndroidX=true
android.enableJetifier=true

我几乎遵循了从 android-testing-master/ui/uiautomator 示例代码中得到的相同内容,但不确定我缺少什么。

【问题讨论】:

  • 重建您的项目,如果问题仍然存在,请使用 gradle 文件同步项目。

标签: android android-studio instrumentation android-uiautomator junit-runner


【解决方案1】:

我也遇到了同样的问题(Android Studio 3.4.2),uiautomator 是红色的:

import androidx.test.uiautomator.UiDevice

“清理项目”和“重建项目”没有帮助,甚至使缓存无效。但是选择另一个 Build Variant 对我有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多