Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Android Gradle Build System build configs package name conflicts with Provider Authority

I've updated my project to use the new Gradle based build system, largely because I've been kind of annoyed that I can't have my app installed on my device to use it since I use the device for development. I saw a lot of promise in the packageNameSuffix offering of the new build system.

The problem that I'm running into involves things other than the package name in the manifest. There are other parts that have to be unique, including permissions (specifically for GCM) and ContentProvider Authorities. When trying to install with a .debug suffix I get errors that the GCM permission for that package hasn't been defined and that I'm trying to install a duplicate provider.

Is there a variable that I can put in my manifest instead of these strings so that the build system will replace those appropriately as well?

like image 608
rharter Avatar asked May 30 '13 15:05

rharter


2 Answers

Here is my solution for GCM problems with packageNameSuffix.

Primary problem is permission names that should have ".debug" suffix. I put that permission to debug and release manifests that are merged to final manifest.

AndroidManfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.experiment.myapplication"
          android:versionCode="1"
          android:versionName="1.0" >

    <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <uses-permission android:name="android.permission.VIBRATE" />
    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
        <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>

</manifest>

debug AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.experiment.myapplication">


    <permission android:name="com.experiment.myapplication.debug.permission.C2D_MESSAGE"
                android:protectionLevel="signature" />
    <uses-permission android:name="com.experiment.myapplication.debug.permission.C2D_MESSAGE" />

    <application>
        <receiver
                android:name=".GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.experiment.myapplication.debug" />
            </intent-filter>
        </receiver>
    </application>

</manifest

>

release Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.experiment.myapplication" >

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

    <application>
        <receiver
                android:name=".GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.experiment.myapplication" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
like image 149
Alexey Zakharov Avatar answered Oct 12 '22 06:10

Alexey Zakharov


This is a current known limitation of changing the package name for a variant. I'm planning on fixing this as soon as possible.

like image 28
Xavier Ducrohet Avatar answered Oct 12 '22 07:10

Xavier Ducrohet