INSTALL_FAILED_DUPLICATE_PERMISSION... C2D_MESSAGE
Asked Answered
H

25

190

I am using Google notifications in my app, and until now I have done below in the manifest:

<!-- GCM -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Keeps the processor from sleeping when a message is received. --> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- This app has permission to register and receive data message. --> 

<!-- Creates a custom permission so only this app can receive its messages. NOTE: APP_PACKAGE.permission.C2D_MESSAGE -->   
<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" />    
<!-- END GCM -->

It worked perfectly until I updated my Nexus 7 to Android 5.0.
Now when I try to install the app in this device with Eclipse, I get this error:

INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.myapp.permission.C2D_MESSAGE pkg=com.myapp

I don't understand what is wrong? It was working perfectly until Android 5.0.
I know that I am using C2D_MESSAGE in two lines, permission and uses-permission but I have copied that code from the original Google GCM guide, so it must be fine.

Harim answered 20/11, 2014 at 15:57 Comment(2)
What you originally took for an obscure bug (well, I did…) is actually a new security feature preventing two apps from declaring the same custom permission that are signed with a different signature, to be installed on a deviceMaramarabel
@Harim Can you please accept the answer as its helpful to many peoples.Mawkish
M
233

I've found a solution that works for me.

In My Device (Nexus 7) Android 5.0. Lollipop I follow these steps.

After Uninstalling App You will find App Name under Apps List of the Downloaded tab.

  • Go to Settings
  • Apps
  • At the bottom of the list, you will find YourApp with a "NOT INSTALLED" Tag
  • Open
  • Click on OptionMenu and Select "Uninstall for all Users"

After these steps, I successfully install the new app and it's running well.

Mawkish answered 13/12, 2014 at 6:52 Comment(9)
I nave nexus 9 with android 5.0.1 and i can't see my app with "noto installed" tagMaudmaude
This worked for me, thanks! My issue was slightly different. I'm doing automated testing (Xamarin.UITest) on our mobile app, and I uploaded a different version for some manual testing. When I attempted to load the app (via VS / Xamarin UITest) to the device, I started seeing this issue. Thanks again.Anthem
This one should be the correct answer: https://mcmap.net/q/134675/-install_failed_duplicate_permission-c2d_messageCalculus
@Pratik Butani The solution worked for me. I would like to know the reason for getting the error?Could you please explain?Selfexplanatory
Its is problem in lollipop only. In that they are not uninstalling app for all user so we have to do that manually. I think.Mawkish
I believe the problem goes further, under marshmallow, the problem persists, in fact under android 6.0.1 uninstalling for all users doesn't fix the problemSloe
I don't find my app at the bottom of the list with NOT INSTALLED tag. What do you mean?Rightward
It would be good to mention that on some versions of Android, you may need to log into each user in turn and uninstall the app, as the application didn't appear under my admin user nor did it show up with the 'pm list packages' command. It only showed up when I logged into the user that had the app installed.Batish
Thanks! I deleted both release and debug versions of the same application.Rosario
C
151

Remove

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

Run App... Then Add the permisson again and Run App.

Ready!.

Chandachandal answered 4/1, 2015 at 15:40 Comment(7)
This answer should be on top as this problem often occurs when you try to install debug and release version of your app on the same device. With this solution you can easily do it. I didn't know you can use variables in the manifest. Upvote!Cowcatcher
This answer does not work if the app is already in production. I cannot expect users of my app to download a new version without the permissions and then install a newer version with the permissions again.Regress
If this is happening to you because you have debug and release versions of your app with different names, then an uninstall is not necessary for it to work: you just need to use the ${applicationId} instead of hardcoding itOakes
The error comes back as soon as I add the permissions again. My phone is Verizon Mottorola with Lollypop 5.1 :(Caroncarotene
Using ${applicationId} instead of static application id solved my problem!! Including when using Flavors!!!!Sheepshank
@yuval's comment is spot on and resolved this for me. Out of the many answer, this one best covers the issue: https://mcmap.net/q/134675/-install_failed_duplicate_permission-c2d_messageBeebe
In which file is this? -> Android manifest file in the "Properties" directory.Banter
C
52

I had the same problem with a custom signature permission on Android-21 and solved it by making sure I was doing a complete uninstall.

This is an edge case that occurs when:

  1. An application defines a custom permission using signature level security
  2. You attempt to update the installed app with a version signed with a different key
  3. The test device is running Android 21 or newer with support for multiple users

Command line example

Here is a command-line transcript that demonstrates the issue and how to solve it. At this point a debug version is installed and I am trying to install a production version signed with the release key:

# This fails because the debug version defines the custom permission signed with a different key:

[root@localhost svn-android-apps]# . androidbuildscripts/my-adb-install Example release
920 KB/s (2211982 bytes in 2.347s)
        pkg: /data/local/tmp/Example-release.apk
Failure [INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.example.android.example.PERMISSION_EXAMPLE_PLUGIN pkg=com.example.android.example]

# I use uninstall -k because apparently that is similar to uninstalling as a user
# by dragging the app out of the app tray:

[root@localhost svn-android-apps]# /android-sdk-linux/platform-tools/adb uninstall -k com.example.android.example
The -k option uninstalls the application while retaining the data/cache.
At the moment, there is no way to remove the remaining data.
You will have to reinstall the application with the same signature, and fully uninstall it.
If you truly wish to continue, execute 'adb shell pm uninstall -k com.example.android.example'

# Let's go ahead and do that:

[root@localhost svn-android-apps]# /android-sdk-linux/platform-tools/adb shell pm uninstall -k com.example.android.example
Success

# This fails again because the custom permission apparently is part of the data/cache
# that was not uninstalled:

[root@localhost svn-android-apps]# . androidbuildscripts/my-adb-install Example release
912 KB/s (2211982 bytes in 2.367s)
        pkg: /data/local/tmp/Example-release.apk
Failure [INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.example.android.example.PERMISSION_EXAMPLE_PLUGIN pkg=com.example.android.example]

# In spite of the warning above, simply doing a full uninstall at this point turned out to 
# work (for me):

[root@localhost svn-android-apps]# /android-sdk-linux/platform-tools/adb uninstall com.example.android.example
Success

# Release version now successfully installs:

[root@localhost svn-android-apps]# . androidbuildscripts/my-adb-install Example release
898 KB/s (2211982 bytes in 2.405s)
        pkg: /data/local/tmp/Example-release.apk
Success

[root@localhost svn-android-apps]# 

Eclipse example

Going in the opposite direction (trying to install a debug build from Eclipse when a release build is already installed), I get the following dialog:

Eclipse reinstall dialog

If you just answer yes at this point the install will succeed.

Device example

As pointed out in another answer, you can also go to an app info page in the device settings, click the overflow menu, and select "Uninstall for all users" to prevent this error.

Cloakroom answered 23/11, 2014 at 15:48 Comment(3)
Thanks, But You should start your answer with "you can also go to an app info page in the device settings, click the overflow menu, and select "Uninstall for all users" to prevent this error."Villarreal
Marry me, please. Following your redaction, I went to Settings > Apps, touch in the old version of the app and in the option menu select "Uninstall for all users".Liquesce
#2 of your precondition list does not have to be true. In my case I'm not updating the app, but installing a debug-build of the same app with different package name as described per this proceudre. https://mcmap.net/q/136859/-how-to-change-the-android-app-package-name-when-assembling-with-gradle. This is an issue I don't see a solution toMailman
B
38

I've solved this without having to resort to uninstalling the alternate apk first (what a pain, right?). To successfully install both a debug and release version of an apk, simply use gradle's built-in ${applicationId} placeholder within the AndroidManifest.xml to modify the permissions' android:name values at compile time.

The build.gradle file snippet:

buildTypes {
    debug {
        applicationIdSuffix ".debug"
        ...
    }
}

The AndroidStudio.xml file snippet:

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

You can inspect the modified AndroidManifest.xml file within the apk using aapt l -a app-debug.apk to ensure the placeholder was properly applied. If you use various product flavors, I'm sure you can apply a variation of this method to suit your needs.

Bitters answered 31/12, 2014 at 2:44 Comment(5)
it seems that if I define different applicationId in two different productFlavors, and use ${applicationId} the effect will be the same.Inna
I think this is more robust solution if you need more then 1 flavor.Inna
this should be marked correct. considering that you can't expect from every coworker to do some hack arounds to simply build a project and install the apkUnknit
Thanks, @jackpile the app runs perfectly fine for me there's just one issue if there are both release and debug builds installed then after installing the debug build the release build opens up insteadCowbind
this should be marked as the correct answer .. thanks @BittersProcyon
U
35

Remove any "Hard Coded" reference of your package name, from your manifest file.

(This is best practice even if you don't using productFlavors)

For example, if your manifest contains:

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

<permission
    android:name="com.yourpackage.name.permission.C2D_MESSAGE"
    android:protectionLevel="signature"/>
<permission
    android:name="com.yourpackage.name.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

Changed it to:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>

<permission
    android:name="${applicationId}.permission.C2D_MESSAGE"
    android:protectionLevel="signature"/>
<permission
    android:name="${applicationId}.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

Then, in your module gradle file, set your relevant applicationId:

signingConfigs {
    stage {
        storeFile file('keystore/stage.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
    production {
        storeFile file('keystore/playstore.keystore')
        storePassword store_password
        keyAlias key_alias
        keyPassword key_password
    }
}

productFlavors {
    staging {
        signingConfig signingConfigs.staging
        applicationId defaultConfig.applicationId + ".staging"
        versionName defaultConfig.versionName + "-staging"
    }

    production {
        signingConfig signingConfigs.production
    }
}

You can follow this tutorial for more info

Uxoricide answered 2/5, 2016 at 22:59 Comment(2)
using ${applicationId} fixed the issue for me!Duplication
How does this adress the issue mentioned?Timikatiming
M
19

try to uninstall the app with adb:

adb uninstall com.yourpackage
Milore answered 26/11, 2014 at 20:37 Comment(3)
Bizarre, I just had to do this on my Nexus 6, even though I had uninstalled my APK through the System UI AND it wasn't showing up under installed apps.Depressive
It gave me Failure [DELETE_FAILED_INTERNAL_ERROR]. What might be the reason?Inconstant
This worked perfectly for me when nothing else would. Thanks for sharing it.Deceitful
A
17

While giving this error it will clearly mention the package name of the app because of which the permission was denied. And just uninstalling the application will not solve the problem. In order to solve problem we need to do the following step:

  1. Go to settings
  2. Go to app
  3. Go to downloaded app list
  4. You can see the uninstalled application in the list
  5. Click on the application, go to more option
  6. Click on uninstall for all users options

Problem solved :D

Apomorphine answered 24/11, 2014 at 13:21 Comment(0)
M
8

Installing an application in OS 5.0 i get this message:

INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.myapp.permission.C2D_MESSAGE pkg=com.myapp

There´s no duplicated packages, and we can solve this issue uninstalling manually the old application or using the adb:

adb uninstall com.yourpackage

Materialism answered 27/1, 2015 at 17:18 Comment(0)
C
6

None of the above worked for me. My app was working fine in previous than Lollipop. But when I tested it on Lollipop the above error came up. It refused to install. I didn't have any previous versions installed so all the above solutions are invalid in my case. But thanks to this SO solution now it is running fine. Just like most developers I followed Google's misleading tutorial and I added the permissions by copy and paste like this:

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

This would work with older versions < Lollipop. So now I changed to:

<uses-permission android:name="com.mycompany.myappname.c2dm.permission.RECEIVE" />
<permission android:name="com.mycompany.myappname.permission.C2D_MESSAGE" 
            android:protectionLevel="signature" />
Caroncarotene answered 4/1, 2016 at 0:52 Comment(0)
F
4

CommonsWare is right, but in my opinion this is a (bug)poor way to say: "The apk installed on the device is signed with a different certificate then the new one you are trying to install".

This is probably a new bug since in the past it used to ask whether or not to uninstall the app from the device due to wrong certificate.

The solution as painful as it may be would be to uninstall the app it manually.

Also what we've done for the sake of team development, we added the debug keystore to our repository, and point gradle to use it like so:

android {
    ...
    signingConfigs {
        debug {
            storeFile file("../certificates/debug.keystore")
        }
    }

    ...

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
    }

    ...
}

And now when passing devices between team members, we all use the same debug certificate, so there is no issue. :)

Futrell answered 30/11, 2014 at 9:25 Comment(0)
P
4

In Android 5, check your settings -> apps. Instead of deleting for just the active user (since android 5 can have multiple users and my phone had a guest user) tap on the accessory button in the top right corner of the action/toolbar and choose "uninstall for all users". It appears that in Android 5 when you just uninstall from launcher you only uninstall the app for the active user.

The app is still on the device.. This had me dazzled to since I was trying to install a release version, didn't work so I thought ow right must be because I still have the debug version installed, uninstalled the app. But than still couldn't install.. First clue was a record in the app list of the uninstalled app with the message next to it that it was uninstalled (image).

Uninstalled app still showing up in apps Uninstalled for all users

Paperback answered 28/12, 2014 at 11:20 Comment(1)
Sry, looked over your comment. We'll just consider this as an extra info post with images.Paperback
S
2

See this link it said that it will work when they are signed by the same key. The release key and the debug key are not the same.

So do it:

buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.release//signing by the same key
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'

        }
        debug {
            applicationIdSuffix ".debug"
            debuggable true
            signingConfig signingConfigs.release//signing by the same key
        }

    }

 signingConfigs {
        release {
            storeFile file("***\\key_.jks")
            storePassword "key_***"
            keyAlias "key_***"
            keyPassword "key_"***"
        }


}
Sunny answered 20/10, 2015 at 15:27 Comment(0)
B
1

replace below lines:

<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" 
android:protectionLevel="signature" /> 
Booklover answered 9/9, 2016 at 4:49 Comment(0)
I
1

In my case, I had several applications installed having the same domain name in the package name as follows.

com.mypackage.app1
com.mypackage.app2
com.mypackage.app3 
...

I had to uninstall all the apps having similar package names and reinstall them again in order to get rid of the problem.

To find all package names from the device I used the following.

adb shell pm list packages

Then I grabbed the packages that match my package name that I am looking for.

dumpsys | grep -A18 "Package \[com.mypackage\]"

Then uninstalled all the apps having that domain.

uninstall com.mypackage.app1
uninstall com.mypackage.app2
uninstall com.mypackage.app3
...

You can also uninstall the applications using the Settings app. Go to the Settings -> Apps -> Find the app -> Uninstall

Hope that helps someone having the same problem as me.

Inconstant answered 18/2, 2020 at 21:18 Comment(0)
H
1

If you have a different flavour of the app, try uninstalling that first. This helped me when I had the same issue.

Hayrick answered 24/2, 2020 at 11:36 Comment(0)
P
0

Previously it used to say that an app with different signature is found on device. When installing from IDE it would also ask do you want to uninstall it?

But I think from Android 5.0 they have changed the reason for uninstallation. It does not happen if you are installing app with the same signature

Pottery answered 25/11, 2014 at 2:22 Comment(0)
H
0

I encountered the same problem with a nexus 5 Android Lollipop 5.0.1:

Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.android.** pkg=com.android.**

And in my case I couldn't fix this problem uninstalling the app because it was an android app, but I had to change my app custom permissions name in manifest because they were the same as an android app, which I could not uninstall or do any change.

Hope this helps somebody!

Heartrending answered 23/12, 2014 at 13:47 Comment(0)
B
0

In my case I received following error

Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.map.permission.MAPS_RECEIVE pkg=com.abc.Firstapp

When I was trying to install the app which have package name com.abc.Secondapp. Here point was that app with package name com.abc.Firstapp was already installed in my application.

I resolved this error by uninstalling the application with package name com.abc.Firstapp and then installing the application with package name com.abc.Secondapp

I hope this will help someone while testing.

Bloater answered 6/10, 2015 at 11:3 Comment(0)
C
0

In your AndroidManifest.xml file, change your specially declared permissions' names, for example:

<!-- Creates a custom permission so only this app can receive its messages. NOTE: APP_PACKAGE.permission.C2D_MESSAGE -->   
<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" />    
<!-- END GCM -->

to this,

<!-- Creates a custom permission so only this app can receive its messages. NOTE: APP_PACKAGE.permission.C2D_MESSAGE -->   
<permission android:name="com.myapprocks.permission.C2D_MESSAGE"  android:protectionLevel="signature" />
<uses-permission android:name="com.myapprocks.permission.C2D_MESSAGE" />    
<!-- END GCM -->

com.myapprocks this part solves the conflict with your other app.

Caerleon answered 16/4, 2016 at 9:4 Comment(0)
J
0

In my case I was using a third party library (i.e. vendor) and the library comes with a sample app which I already had install on my device. So that sample app was now conflicting each time I try to install my own app implementing the library. So I just uninstalled the vendor's sample app and it works afterwards.

Johnnajohnnie answered 23/5, 2016 at 20:58 Comment(0)
K
0

I uninstalled previous version. It worked for me.

Know answered 5/10, 2018 at 2:47 Comment(0)
C
0

I restarted my phone after uninstalling the app and it worked

Courtship answered 4/12, 2018 at 10:10 Comment(0)
S
0

I had another app using a plugin with this permission authorities. I uninstalled other apps which use this same package and all worked

Shostakovich answered 8/5, 2022 at 23:6 Comment(0)
D
0

In my case, I had built my App with one AppID and then wanted to build it with a new AppID and this is when I received the error.

I am using Unity with the OneSignal and FirebaseCommon Android Plugins. These plugins themselves contained the following lines in their manifest files:

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

I saw that by unzipping their .aar files. It was quite hidden.

I resolved the issue by using the Android Dependency Resolver for Unity and I did a full Force Resolve which in turn changed the manifests with my new AppId (because as you can see the actual permission string is built using a variable).

Dorking answered 5/5, 2023 at 13:28 Comment(0)
A
0

In my case, I was having this error because I had the app install from the Play Store, at the same time I was developing on Android Studio, so when I was trying to run the app from Android Studio I had the same error, so I just uninstall the app that I downloaded from the Play Store and as simple as that the error was gone.

Amphibiotic answered 25/1 at 23:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.