gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:42:10 27 4
gpt4 key购买 nike

我正在尝试使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com