我正在尝试使用InstrumentedTest在Android Studio中编写性能测试。我为性能测试制作了一个单独的模块。这取决于项目中的其他模块。为了使我的性能测试准确,我希望我的performancetest
模块依赖于其他模块的发布配置。
例如,如果我的项目中有以下三个模块: -:foo
-:bar
-:performancetest
我希望模块:performancetest
中的ExampleInstrumentedTest
练习和测量: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
的发布版本?
我想我想通了。
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
}
}
}