Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a Android gradle build, how to change the package name by build type?

In a Android gradle build, I can simply let the build "overwrite" the package name by flavor like so:

productFlavors {
    free {
        applicationId "net.company.appname.free"
    }

    paid {
        applicationId "net.company.appname.paid"
    }
}

Can I do the same by build type?

It looks like I can only add suffixes:

buildTypes {
    debug {
        applicationIdSuffix ".debug"
}
    release {
        ...
    }
}
like image 782
treesAreEverywhere Avatar asked Mar 20 '14 21:03

treesAreEverywhere


People also ask

How do I change a Gradle package name?

gradle (Module: app) in Gradle Scripts. Here change the applicationId and click on Sync Now. And you are successfully renamed your package name.

Can I change Android package name?

Right-click on the package name you want to change and use the Refactor > Rename… option again. Select Rename all when prompted by Android Studio.

How do I change my build type?

NOTE: By default, the Android Studio will generate "debug" and "release" Build Types for your project. So, to change a Build Type, all you need to do is just select your Build Type from the Build Variant and after the project sync, you are good to go.


1 Answers

A bit late on with the answer, but you could have a common part of the applicationID defined such as:

android { 
  defaultConfig { 
    applicationId 'net.company.appname'
    ...
  }
}

and have your flavours specify the applicationIdSuffix as in your example, so that'd give you the 'net.company.appname.debug' and 'net.company.appname.release' or whatever you say you want the suffix to be.

like image 77
SteveC Avatar answered Sep 20 '22 11:09

SteveC