androidbuild.gradleandroid-productflavorscode-maintainability

How Android Product Flavors and Configuration help to maintain and support single code base to distribute multiple client


I have a requirement Android Product Flavors and Configuration help to maintain and support single code base to distribute multiple clients. I referred few links, It gives a basic idea. My question is actually Am I'm going correct direction. I very new to this kind scenario.

eg: Product name: MohanApp client 1: Cartoon, client 2: Disney, client 3: Pogo,

flavorDimensions "app", "server"
    productFlavors {
        cartoon {
            dimension "app"
            applicationId 'com.cc.whitelabel.cartoon'
            manifestPlaceholders = [
                    appIcon: "@drawable/cartoon_network"
            ]
        }
        disney {
            dimension "app"
            applicationId 'com.cc.whitelabel.disney'
        }
        pogo {
            dimension "app"
            applicationId 'com.cc.whitelabel.pogo'
        }
        dev {
            dimension "server"
        }
        staging {
            dimension "server"
        }
        production {
            dimension "server"
        }
    }

Thanks in Advance.


Solution

  • I found the solution for the Android WhiteLabeling/App Branding/ProductFalvours, Here I share my build.gradle for creating app branding. the gradle file syntax may vary based on the version of IDE.

    Tools:

    Android Studio IDE:3.1

    Target Version:27

    AppModule build.gradle

    android {
        compileSdkVersion 27
    
        defaultConfig {
            applicationId "com.appmohan"
            minSdkVersion 21
            targetSdkVersion 27
            versionCode 2
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        // APK signing configuration
        android.signingConfigs {
            MobileApp { }
        }
    
        flavorDimensions "app"
        productFlavors {
            cartoon {
                dimension "app"
                applicationId "com.appmohan.cartoon"
                versionName '1.0.1'
                versionCode 2
                minSdkVersion 21
                targetSdkVersion 26
            }
            disney {
                dimension "app"
                applicationId "com.appmohan.disney"
                versionName "1.0.1"
                versionCode 2
                minSdkVersion 21
                targetSdkVersion 26
            }
            pogo {
                dimension "app"
                applicationId "com.appmohan.pogo"
                versionName "1.0.1"
                versionCode 2
                minSdkVersion 21
                targetSdkVersion 26
            }
        }
    
    
        android.buildTypes {
            debug {
                //do our url stuff
            }
            stagging {
                //do our url stuff
            }
            release {
                //do our url stuff
            }
        }
    
        sourceSets.cartoon{
            res.srcDirs = ['res', 'src/cartoon/res']
        }
        sourceSets.disney{
            res.srcDirs = ['res', 'src/disney/res']
        }
        sourceSets.pogo{
            res.srcDirs = ['res', 'src/pogo/res']
        }
    }
    

    For experimental and education purpose I created this app. GitHub Link AndroidWhiteLabel/App Branding/ProductFalvour Thanks to Android Studio to achieve the result.And thanks to all my referral authors.

    Happy Coding:)