Resolve Duplicate Permission Problem in Android Package

Standard

Android application has unique identifier called package name to prevent duplicate installation. The standard convention name for Android package name is reversed web URL.

In development process, developers may need to separate application into some versions for testing purpose. For example, we need beta version to be tested before it’s released on the marketplace. We can separate them using different flavors definition in gradle script.

But it can be problem when we use the package name in the manifest file. So we may need to adjust the manifest too.

For example, if we use GCM (Google Cloud Messaging) to enable push notification we need to add permission with unique name (so it has to be the package name). So for different package name it need different permission or there will be problem with duplicate permission. Here we need to define another permission with specified package name and remove the previous permission definition when merging the manifest.

These are the sample code of different manifest file for different package name in different flavor.
Main AndroidManifest.xml

<permission
android:name="com.packagename.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.packagename.app.permission.C2D_MESSAGE" />

Beta AndroidManifest.xml

<permission
android:name="com.packagename.app.permission.C2D_MESSAGE"
android:protectionLevel="signature"
tools:node="remove" />
<uses-permission
android:name="com.packagename.app.permission.C2D_MESSAGE"
tools:node="remove" />

<permission
android:name=”com.betapackage.app.permission.C2D_MESSAGE”
android:protectionLevel=”signature” />
<uses-permission android:name=”com.betapackage.app.permission.C2D_MESSAGE” />