Search code examples
androidbuildapkandroid-productflavorsbuildconfiguration

Create separate apk for separate flavor in android


I have used build.gradle(app) to create different flavors of apk. But installing different flavors of same apk overrides the previous one. I want to create different apks to run on same device simultaneously. I want to create different apk with different appicon which can be installed on same device and run simultaneously. Any link or tutorial or direct help is appreciated.

Thanks in advance.


Solution

  • Change the PackageName of the flavor

    Sample Gradle File

    apply plugin: 'com.android.application'
    
    android {
    
        lintOptions {
            abortOnError false
        }
    
    
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 16
        }
    
        buildTypes {
            debug {
                minifyEnabled false
                zipAlignEnabled true
            }
            release {
                minifyEnabled true
                zipAlignEnabled true
            }
        }
        productFlavors {
            Flavor1 {
                applicationId "com.falvor.one" //This is where you change the package name
            }
            Flavor2 {
                applicationId "com.falvor.two"
            }
        }
    }
    

    Flavor Hierarchy in Android

    - src/main/java
    - src/flavor1
    --------------Java
    ----------------Your java files
    --------------res
    ----------------Drawable
    
    • src/flavor2/java

    For more understanding, follow this link