Unable to build feature modules in a multi-flavor app

前端 未结 3 1513
清酒与你
清酒与你 2021-01-18 11:00

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

相关标签:
3条回答
  • 2021-01-18 11:39

    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.

    0 讨论(0)
  • 2021-01-18 11:57

    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"
        }
    }
    
    0 讨论(0)
  • 2021-01-18 11:57

    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

    0 讨论(0)
提交回复
热议问题