androidandroid-buildandroid-productflavorsbuildconfigurationbuild-environment

Create separate apk for separate flavor in android to run on same device


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/"'
    }

}

Solution

  • 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"