Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use different package names between flavors?

I'm trying to create a single project with 2 flavors: free and pro (versions).

My app is already in PlayStore with different packages (E.g.: com.example.appfree and com.example.app)

This is my build.gradle:

defaultConfig {    applicationId "com.example.appfree" } productFlavors{    lite {        applicationIdSuffix 'lite'    }     pro {     } } 

And this is my manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest     xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.app">      <application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsRtl="true"         android:theme="@style/AppTheme">          <activity             android:name=".SplashScreenActivity"             android:label="@string/app_name">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>          <activity android:name=".MainActivity"/>      </application>  </manifest> 

I tried to upload a build apk for free and pro flavors. Pro flavor is ok, but free flavor isnt accepted by Google, because the package is incorrect. How can I solve this?

====== Solved: ====== applicationIdSuffix only works with buildTypes.

like image 406
Felipe Porge Xavier Avatar asked Sep 17 '16 23:09

Felipe Porge Xavier


People also ask

Does package name matter?

package Id (bundle Id is name used on iOS) does not really matter except for the moments you see it like in the case of play store links. Yet, the only thing that technically matters is to make it unique among all published apps (which it is the case, otherwise you would not be able to publish).

How do you fix you need to use a different package name because COM example is restricted?

The package name is the identitiy of the application. To rename the package name, In eclipse right click on the project in project explorer. Then Android Tools > rename Aplication Package name. Then enter the new package name.

Is package name same as app name?

All Android apps have a package name. The package name uniquely identifies the app on the device; it is also unique in the Google Play store.


1 Answers

With the new Android Gradle build system, you can easily build multiple different versions of your app; for example, you can build both a "free" version and a "pro" version of your app (using flavors), and these should have different packages in the Google Play store such that they can be installed and purchased separately, both installed at the same time, and so on. Similarly, you may also build both "debug" and "alpha" and "beta" versions of your app (using build types) and these can also similarly contribute to unique package names.

app/build.gradle:

apply plugin: 'com.android.application' android {     compileSdkVersion 19     buildToolsVersion "19.1"     defaultConfig {         applicationId "com.example.my.app"         minSdkVersion 15         targetSdkVersion 19         versionCode 1         versionName "1.0"     } ... 

app/build.gradle:

productFlavors {     pro {         applicationId = "com.example.my.pkg.pro"     }     free {         applicationId = "com.example.my.pkg.free"     } }  buildTypes {     debug {         applicationIdSuffix ".debug"     } } .... 

from Android Studio Project Site - ApplicationId versus PackageName

like image 142
Veener Avatar answered Sep 20 '22 01:09

Veener