我有一个多维的android gradle项目,需要很长时间才能构建并且需要长时间测试。我有一个二维的flaver定义。第一个维度有2个项目值,第二个维度有4个环境定义,有3个构建类型。
这导致2x4x3 = 24个构建变体。我想以某种方式进行优化,只构建一个构建变体,并且只有一个构建变体用于在ci环境中运行单元测试。
的build.gradle
android {
// more configurations
flavorDimensions "project", "environment"
productFlavors {
basic {
dimension "project"
}
advanced {
dimension "project"
}
flavorDevelopment {
dimension "environment"
applicationId "ch.myproject.app.development"
}
flavorTest {
dimension "environment"
applicationId "ch.myproject.app.test"
}
flavorIntegration {
dimension "environment"
applicationId "ch.myproject.app.integration"
}
flavorProduction {
dimension "environment"
applicationId "ch.myproject.app.production"
}
buildTypes {
debug {
testCoverageEnabled = true
minifyEnabled = false
shrinkResources = false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debugInstantRun.initWith(buildTypes.debug)
debugInstantRun {
// we are changing this build variant later on runtime, so that it will use constant values
// for versionCode and versionName in the Manifest, for make sure the
// manifest is unchanged between the instantRun builds
// Specifies a sorted list of fallback build types that the
// plugin should try to use when a dependency does not include a
// "debugInstantRun" build type. You may specify as many fallbacks as you
// like, and the plugin selects the first build type that's
// available in the dependency.
matchingFallbacks = ['debug']
}
release {
// Currently all environments (dev/test/int/prod) are signed by the Production certificates
minifyEnabled = false
shrinkResources = false
}
}
// more configurations
} // end of android
我以前会清理一切,gradlew clean --refresh-dependencies
然后只是组装Debug变体,gradlew assembleDebug
然后我尝试在一个调试变量上运行unittest:gradlew testAdvancedFlavorDevelopmentDebugUnitTest
- >这不起作用
如果我运行qazxsw poi所有构建变体都是构建的(除了Release构建类型),测试工作正常但这需要很长的时间!
也尝试了gradlew test
- >不起作用
我想我可以将单元测试移动到另一个目录而不是测试例如testAdvancedFlavorDevelopment然后当我输入gradlew testDebugUnitTest
时,只会测试testAdvancedFlavorDevelopmentDebug和testAdvancedFlavorDevelopmentDebugInstantRun的测试。
但必须有一种方法让测试在测试目录中,并由gradlew命令强制执行,只需编译和单元测试一个特定的构建变体!有任何想法吗?
蒂亚卢克