rharter
rharter

Reputation: 2495

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?

Upvotes: 12

Views: 1866

Answers (4)

moonlight
moonlight

Reputation: 359

You can use:

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

Android will add the current package name automatically, as you started with a ..

Upvotes: 1

Victor91
Victor91

Reputation: 455

I've replaced all my app's package name in AndroidManifest.xml with placeholder ${packageName}, so Manifest Merger does all work

For example:

<uses-permission android:name="${packageName}.permission.C2D_MESSAGE" />

Upvotes: 1

Alexey Zakharov
Alexey Zakharov

Reputation: 25112

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>

Upvotes: 7

Xavier Ducrohet
Xavier Ducrohet

Reputation: 28549

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

Upvotes: 6

Related Questions