I am using Gradle 4.4 with Gradle-Android plugin 3.1.1 on Android Studio 3.1.1.
I have 2 flavors \'a\' and \'b\' and I am unable to build my project due to the follo
It seems you didn't specify difference in the names of a
and b
packages. Below is my working implementation of flavor
feature for API 25 and com.android.tools.build:gradle:2.3.1
in the app
level build.gradle
of AS 2.3.3:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.00"
}
signingConfigs {
config {
storeFile file(STORE_PATH)
keyAlias KEY_ALIAS
keyPassword KEY_PASSWORD
storePassword KEYSTORE_PASSWORD
}
}
productFlavors {
nosync {
applicationIdSuffix ".nosync"
versionNameSuffix '-nosync'
signingConfig signingConfigs.config
}
sync {
signingConfig signingConfigs.config
}
}
buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
signingConfig signingConfigs.config
}
}
dependencies {
...
}
Take a look on difference
applicationIdSuffix ".nosync"
versionNameSuffix '-nosync'
between nosync
and sync
flavors. It will change the package name of nosync
apk
.
Thanks to user TWL who pointed me towards google samples for instant apps, with an example for flavors.
We need flavor declarations in all the feature modules, application module and instant-app module as well. Library modules can be skipped as of today with plugin version 3.1.1. In other words, have this section in all feature and installed/instant modules:
flavorDimensions "dim"
productFlavors{
a{
dimension "dim"
}
b{
dimension "dim"
}
}
FWIW you don't have to have matching flavors in your modules. You can tell it to fallback to the default build types.
By using matchingFallbacks
buildTypes {
aDebug {
testCoverageEnabled true
matchingFallbacks = ['debug']
}
bDebug {
testCoverageEnabled true
matchingFallbacks = ['debug']
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// This one already looks for 'release' which is added by default, so no need for fallback
}
}
https://developer.android.com/studio/build/dependencies#resolve_matching_errors