android-studio - 在 Gradle 中,如何指定我的 androidTest 实现应依赖于项目模块的发布版本?

标签 android-studio gradle android-gradle-plugin

我正在尝试使用 InstrumentedTest 在 Android Studio 中编写性能测试。我为我的性能测试制作了一个单独的模块。这取决于项目中的其他模块。为了使我的性能测试准确,我想要我的 performancetest模块依赖于其他模块的发布配置。

例如,如果我的项目中有这三个模块:
- :foo - :bar - :performancetest
我想要 ExampleInstrumentedTest在模块 :performancetest练习和测量 :foo 的发布版本和 :bar .

我该如何配置?我正在尝试使用:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(path: ':foo', configuration: 'release')
    implementation project(path: ':bar', configuration: 'release')
}

但是当我同步它时,我收到了这个错误:
Execution failed for task ':performancetest:androidDependencies'.
> Could not resolve all artifacts for configuration ':performancetest:debugCompileClasspath'.
   > Could not resolve project :foo.
     Required by:
         project :performancetest
      > Project :performancetest declares a dependency from configuration 'implementation' to configuration 'release' which is not declared in the descriptor for project :foo.

但我绝对可以构建 :foo 的发布版本.

我如何申报我的:performancetest依赖 :foo 的发布版本和 :bar ?

最佳答案

我想我想通了。

性能测试.build.gradle

android {
    // We want our performance test to run with the _release_ version of our libraries
    // so we make the test type "release" which will choose the release version of all the
    // modules
    // However, I get a signing error when Android has run a test apk built with the release
    // build type. So, by inheriting the debug buildType into the release configuration, we
    // end up with:
    //
    // 1. release versions of all our library code
    // 2. debug version of the testing code with debug apk packaging.
    //
    // This runs successfully on the devices.
    testBuildType "release"
    buildTypes {
        release {
            initWith debug
        }
    }
}

关于android-studio - 在 Gradle 中,如何指定我的 androidTest 实现应依赖于项目模块的发布版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52191532/

相关文章:

scala - Gradle编译的Scala类与IntelliJ不兼容吗?

classpath - Gradle无法正确安装

android - Kotlin DSL 构建脚本依赖更新

java - Android Studio 卡在加载屏幕上

android - 第一次进入应用程序的教程?

java - 退出主 list 时出现错误 :Validation failed,,并且属性在 AndroidManifest.xml 中使用-feature#20000@glEsVersion

Android Studio 向 "Update google-services plugin or updating com.google.android.gms"询问 Firebase 身份验证和数据库

android - 在 Android Studio 中重新排列 Logcat 按钮

java - Jacoco:对于报告生成,必须使用与运行时相同的类文件

Android Studio 说我不在 gradle build 上,但我在