1

I have already asked similar question But could not find what i seek . Hence asking again . I want to run separate flavor apk on same device simultaneously.

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.

My build.gradle is as below

 productFlavors {
    production {
        applicationId
        "com.abc.def"
        buildConfigField 'String', 'HOST', '"http://example.com/api/"'
    }
    staging {
        applicationId
        "staging.com.abc.def"
        buildConfigField 'String', 'HOST', '"http://example.com/api/"'
    }
    backendtesting {
        applicationId
        "backendtesting.com.abc.def"
        buildConfigField 'String', 'HOST', '"http://example.com/api/"'
    }

}
SimpleCoder
  • 1,665
  • 1
  • 21
  • 34

3 Answers3

2

This post explains step by step how to configure your directory structure and gradle file.

The main steps are:

  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

2

Do not put line breaks between the gradle command and it's argument. It will read each line separately since line breaks are command separators for gradle.(like how ; is for java)

For example, use:

applicationId "com.abc.def"

instead of

applicationId
"com.abc.def"
SilverCorvus
  • 2,956
  • 1
  • 15
  • 26
1

You can set different applicationId for different flavors. In this way different flavors will be treated as different applications and will not overwrite each other when you install them on same device.

As an example, following snippet will create two flavors, prod and dev with different app packages. You can install them both together on the device.

productFlavors {
        dev {
            applicationId "com.swagata.devbuild"
        }

        prod {
            applicationId "com.swagata.prodbuild"
        }
    }
Swagata Acharyya
  • 647
  • 4
  • 10
  • I have edited the question with my code snippet of gradle file. I already used this approach. But it is not working. please check and suggest if anything i am missing. thanks in advance. – SimpleCoder Oct 15 '15 at 06:23
  • @SimpleCoder How are you creating different apks for different flavors? `./gradlew assemble` creates different apks that can run independently if you follow this approach. – Swagata Acharyya Oct 18 '15 at 08:40