Hi i am trying to build a androidTest APK based on a flavour and a custom build type i have defined below:
productFlavors {
FlavourOne {
applicationIdSuffix ".live"
buildConfigField 'String', 'SERVER_BASE_URL', '"http://live.com"'
}
FlavourTwo {
applicationIdSuffix ".demo"
buildConfigField 'String', 'SERVER_BASE_URL', '"http://demo.com"'
}
}
buildTypes {
debug {
minifyEnabled false
// shrink code (remove unused classes and methods) - note that it falls back to experimental shrinker for Instant Run
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-debug.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-test.pro'
}
release {
minifyEnabled true // shrink code (remove unused classes and methods)
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debugDemo {
applicationIdSuffix '.demo'
versionNameSuffix '-DEMO'
minifyEnabled false
// shrink code (remove unused classes and methods) - note that it falls back to experimental shrinker for Instant Run
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-debug.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-test.pro'
}
demo {
applicationIdSuffix '.demo'
versionNameSuffix '-DEMO'
minifyEnabled true // shrink code (remove unused classes and methods)
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
When i run gradlew assembleFlavourOneDebugDemoAndroidTest
i get an error straight away saying
Task 'assembleFlavourOneDebugDemoAndroidTest' not found in root project 'MyProject'.
It works fine if i omit my custom buildType and just do assembleFlavourOneAndroidTest
and it works. It also works if do assembleFlavourOneDebugANdroidTest
only...
In your build. gradle (:app): tasks. all { Task task -> if (task.name == "preDebugBuild") { doFirst { //for debug build } } else if (task.name == "preReleaseBuild") { doFirst { //for release build } } } dependencies { ... }
A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.
I faced the similar problem, I need debug build type when develop, debugMinify build type when run androidTest on pipeline or assembleAPK
so follow bellow code , You can run androidTest on debug type when develop and when you run assemble APK command , testBuildType will be changed
android{
buildTypes{
release{}
debug{}
debugMinify{}
}
testBuildType getCurrentVariant()
}
def getCurrentVariant() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
println(tskReqStr)
if (tskReqStr.contains("assemble") && tskReqStr.contains("DebugMinify")) {
print("buidType: debugMinify")
return "debugMinify"
} else {
print("buidType: debug")
return "debug"
}
}
and
gradlew assembleDevelopDebugMinify
gradlew assembleDevelopDebugMinifyAndroidTest
[DefaultTaskExecutionRequest{args=[assembleDevelopDebugMinify],projectPath='null'}]
buidType: debugMinify
According to the documentation only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:
android {
testBuildType "demo"
}
and your gradle task after sync should look like this:
./gradlew assembleFlavourOneDemoAndroidTest
and be careful there will be NO debug as you pointed out in your description at the end.
assembleFlavourOne
DebugDemoAndroidTest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With