Unable to build feature modules in a multi-flavor app

廉价感情. 提交于 2019-12-01 18:12:03

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"
    }
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!