Create separate apk for separate flavor in android
Asked Answered
F

3

6

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.

Foreconscious answered 14/10, 2015 at 13:5 Comment(4)
change the package name of each flavorRiver
let me try this approach ,will update shortly.Foreconscious
@Murtaza, if package name changes , referring to those files in "main->java" folder would be handled manually ?Foreconscious
@Mortaza , is it creating 2 different app icon in menu for flavor1 and flavor2 simultaneously ? I tried it , but it is replacing each other while installing .Foreconscious
R
4

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

River answered 14/10, 2015 at 13:12 Comment(7)
where i can define icon for each flavorLucilucia
You need to create a folder in src named "Flavor1" and "Flavor2" respectively. in each of that folder you need to create a same hierarchy as of MAIN folderRiver
could u give me some link of github where it is done,because i tried it but i did not get successLucilucia
@ Ashish, @Mortaza , is it creating 2 different app icon in menu for flavor1 and flavor2 simultaneously ? I tried it , but it is replacing each other while installing .Foreconscious
Then you are doing it wrong. Follow the link in my answer, you'll know how to separate files for each environmentRiver
It is working on mac and not in windows. I dont know why .Foreconscious
It has nothing to do with the OS.River
M
3

You need to create new productFlavors in your gradle file, like this;

productFlavors {
        Flavor1 {
            applicationId 'com.project.fl1'
            signingConfig signingConfigs.xx
            versionCode 1
        }
        Flavor2 {
            applicationId 'com.project.fl2'
            signingConfig signingConfigs.xx
            versionCode 1
        }
        Flavor3 {
            applicationId 'com.project.fl3'
            signingConfig signingConfigs.xx
            versionCode 1
        }
}

The important thing here is to give each one a unique applicationId, they can then be installed on the same phone.

Maffa answered 14/10, 2015 at 13:13 Comment(0)
H
2

This post explains exactly how to achieve what you want step by step.

Most importantly:

  1. add the product flavours container to the app build.gradle file

    productFlavors { free { applicationId "antoniocappiello.com.buildvariantsexample.free" } paid { applicationId "antoniocappiello.com.buildvariantsexample.paid" } }

  2. create inside src a directory with the exact name of the product flavour that you want to look different from the main variant, for example with the configuration at step 1 the directory name could be paid or free . And inside that directory create the subfolder res/drawable where you are going to place your new app launcher icon.

Directory structure example

Hemolysis answered 25/10, 2015 at 17:53 Comment(1)
@Foreconscious you were looking for a tutorial and I provided it to you. Didn't you liked my answer https://mcmap.net/q/1692019/-create-separate-apk-for-separate-flavor-in-android ?Hemolysis

© 2022 - 2024 — McMap. All rights reserved.