How to change the Android app package name when assembling with Gradle?

android, android-build, android-gradle-plugin, gradle

Solution

You could so something like this

android {
    ...

    defaultConfig {
        minSdkVersion 8
        versionCode 10
    }

    flavorDimensions "flavor1", "flavor2"

    productFlavors {
        flavor1 {
            applicationId "com.example.flavor1"
            versionCode 20
        }

        flavor2 {
            applicationId "com.example.flavor2"
            minSdkVersion 14
        }
    }
}

You can also change the field `android.defaultConfig.applicationId` if you want to do one-off builds.

Taken from: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-Flavor-Configuration

Problem

Is it possible to change the package name of an Android application using Gradle? I need to compile two copies of the same app, having a unique package name (so I can publish to the market twice).

Original source

Related problems