5

I'm getting this error:

Permission name C2D_MESSAGE is not unique (appears in both my.packagename.permission.C2D_MESSAGE and my.packagename.acc.permission.C2D_MESSAGE) (Previous permission here)

enter image description here

In my Android manifest:

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

The problem started after adding the applicationIdSuffix to a flavor in build.gradle (which at first glance seemed to have nothing to do with it).

Build.gradle:

flavorDimensions "type"
productFlavors {
    acceptance {
        dimension="type"
        applicationIdSuffix ".acc"
        versionNameSuffix "-acc"
    }
    production {
        dimension="type"
        applicationIdSuffix ""
        versionNameSuffix ""
    }
}

Application.java:

    if (BuildConfig.DEBUG) {
        GoogleAnalytics.getInstance(context).setDryRun(true);
    } else {
        setupGoogleAnalytics();
    }

I've created a copy of google-services.json.

I've added google-services.json to:

 app\src\acceptance\google-services.json (fake numbers)

 app\src\production\google-services.json

I've made different bogus values for the keys in the acceptance. I don't want Google Analytics in the acceptance version. So I prefer to not create a separate google-services.json. Is this possible?

Simply removing the permission in manifest doesn't work for API<23.

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

3 Answers3

2

This looks like you're using the latest Firebase Cloud Messaging (FCM) SDK but retaining the old GCM permissions. The FCM SDK automatically injects the necessary permissions into your manifest at build time.

Remove the C2D_MESSAGE permission from your manifest per the migration guide here: https://developers.google.com/cloud-messaging/android/android-migrate-fcm

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
2

add a new androidmanifest into:

app\src\acceptance\androidmanifest.xml

and add the "acc" prefix:

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

<!--this needs to be in there for API 23 and lower-->
<permission
    android:name="my.packagename.acc.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="my.packagename.acc.permission.C2D_MESSAGE" />

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94
1

This problem often occurs when you try to install debug and release version of your app on the same device.

In order to fix this bug, you try uninstalling and reinstalling the app.

About source code in file AndroidManifest.xml:

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

I think your permission is OK.

chaunv
  • 833
  • 6
  • 15