【问题标题】:Android Studio does not resolve androidTestImplementation dependencies in custom project layoutAndroid Studio 无法解析自定义项目布局中的 androidTestImplementation 依赖项
【发布时间】:2019-04-29 07:46:10
【问题描述】:

我有一个使用非标准源文件夹布局的项目,如下所示:

sourceSets {
    androidTest {
        manifest.srcFile "/myproject/androidTest/AndroidManifest.xml"

        java {
            srcDirs = [
                "/myproject/androidTest/java"
            ]
        }
    }
}

Android Studio 很好地显示了上述源文件夹,并在树中将其标记为“androidTest”。现在的问题始于 espresso 等依赖项在任何测试中都没有解决(在 AS 中找不到类) - 尽管它们已被正确声明为:

 androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

如果我将 'androidTestImplementation' 更改为 'implementation' Android Studio 将恢复并能够解决依赖项(但我不想将测试依赖项添加到我的实现范围!)

这只是 Android Studio 3.2.1 中的错误还是我的设置中存在错误?

【问题讨论】:

  • 尝试使用 3.0.2 执行 androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'。它对我来说很好。
  • 你还在报错吗?
  • 3.0.2 产生同样的错误
  • 你找到解决办法了吗?我有同样的情况,在 androidTest 下列出的所有库都无法从测试文件中访问。
  • 仍然没有修复:(

标签: android android-studio gradle ide dependencies


【解决方案1】:

遇到了同样的问题。并意外找到了解决方案...

只需使用括号......所以在你的情况下是:

androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2')

【讨论】:

    猜你喜欢
    • 2019-03-31
    • 1970-01-01
    • 2013-12-12
    • 2019-06-08
    • 2017-05-18
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多