Search code examples
android-gradle-plugingradle-eclipse

Generating more than one apk , with same resources , with different app names , using Gradle


I'm just getting my first steps using Gradle on android projects,just can i know if it's possible to generate two apk with different app names , and SAME resources ,using gradle. to concreticize more : i want to compile a Helloworld project , and generate 2 apk with different names. is it possible and how ?

thanks .


Solution

  • Yes, using the product Flavors mechanism.

    You'll write:

    android {
      productFlavors {
        flavor1 {
          packageName "com.my.package.name.1"
        }
        flavor2 {
          packageName "com.my.package.name.2"
        }
      }
    }
    

    With all your sources in the default source folder (src/main/java) and the default manifest (src/main/AndroidManifest.xml), you'll automatically get 2 apps which only differ in the package name in their manifest.

    Documentation: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants