gdogaru
gdogaru

Reputation: 521

Mobile app clones from same codebase

I have an android app that I want customized for different clients, usually changed colors.

I could use flavors, but The problem is that every app should have 2 stages (so, 2 apps for every client), 1 for QA and 1 for Prod and they use different rest-api urls, custom for each client.

What would be ideal for me is a way to nest flavors so I can define properties for each,but it's not supported. This will also allow me to modify some layouts for client_1 and use the rest from main, which I also need to do. Example:

 productFlavors {
    client_1 {
        dev {
            buildConfigField "String", "API_URL", "https://...."
        }
        prod {
            buildConfigField "String", "API_URL", "https://...."
        }
    }
    client_2 {
        dev { //...
        }
        prod {
            //...
        }
    }
}

Any idea how I can achieve that?

The other option would be to have a common library app and have different apps for different clients with their config, but that would make it more complex.

Upvotes: 1

Views: 106

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 365058

When the app is based on more than one criteria, instead of creating a lot of flavors you can define flavor dimensions.

The flavor dimensions define the cartesian product that will be used to produce variants.

Example:

flavorDimensions("dimA", "dimB")

productFlavors {

    row1 {
        ...
        dimension = "dimA"
    }
    row2 {
        ...
        dimension = "dimA"
    }
    row3 {
         ...
        dimension = "dimA"
    }

    col1 {
        ...
        dimension = "dimB"
    }
    col2 {
        ...
        dimension = "dimB"
    }
    col3 {
         ...
        dimension = "dimB"
    }
}

This config will produce 18 (3*3*2) variants (if you have the 2 standard build types : debug and release). The following build variants will be created:

row1-col1-debug 
row1-col2-debug 
row1-col3-debug 
row1-col1-release
row1-col2-release
row1-col3-release

row2-col1-debug 
row2-col2-debug 
row2-col3-debug 
row2-col1-release
row2-col2-release
row2-col3-release

row3-col1-debug 
row3-col2-debug 
row3-col3-debug 
row3-col1-release
row3-col2-release
row3-col3-release

Upvotes: 2

Krish
Krish

Reputation: 3885

In my project i used , build types with product flavours. I will explain it here. My project looks like this,enter image description here

and add this lines in the gradle file,

buildTypes {
        prod {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        dev {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    productFlavors {

        client_1 {
            applicationId "com.example.client_1"
            versionCode 1
        }

        client_2 {
            applicationId "com.example.client_2"
            versionCode 1
        }

    }

Upvotes: 2

Related Questions