我正在尝试通过使用InstrumentedTest在Android Studio中编写性能测试。我为性能测试制作了一个单独的模块。它取决于项目中的其他模块。为了使性能测试更加准确,我希望我的performancetest
模块依赖于其他模块的 release 配置。
例如,如果我的项目中包含以下三个模块:
-: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
的 release 版本?
答案 0 :(得分:0)
我想我明白了。
performancetest.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
}
}
}