INSTALL_FAILED_DUPLICATE_PERMISSION... C2D_MESSAGE
Solution 1
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.
Solution 2
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!.
Solution 3
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:
- An application defines a custom permission using signature level security
- You attempt to update the installed app with a version signed with a different key
- 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:
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.
Solution 4
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.
Solution 5
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
}
}
Related videos on Youtube
NullPointerException
Updated on July 20, 2022Comments
-
NullPointerException almost 2 years
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 usingC2D_MESSAGE
in two lines,permission
anduses-permission
but I have copied that code from the original Google GCM guide, so it must be fine.-
AZ_ over 9 yearsWhat 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 device
-
Pratik Butani about 2 years@NullPointerException Can you please accept the answer as its helpful to many peoples.
-
-
yajnesh over 9 yearsThanks, 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."
-
Jon Willis over 9 yearsBizarre, 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.
-
Jordy over 9 yearsSry, looked over your comment. We'll just consider this as an extra info post with images.
-
Rudolf Real over 9 yearsMarry 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".
-
Nilzor about 9 years#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. stackoverflow.com/a/21006552/507339. This is an issue I don't see a solution to
-
xXJohnRamboXx about 9 yearsI nave nexus 9 with android 5.0.1 and i can't see my app with "noto installed" tag
-
grandouassou about 9 yearsThis 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!
-
LuFaMa over 8 yearsThis 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.
-
Robert over 8 yearsit seems that if I define different
applicationId
in two differentproductFlavors
, and use${applicationId}
the effect will be the same. -
Robert over 8 yearsI think this is more robust solution if you need more then 1 flavor.
-
Sharjeel over 8 yearsThis one should be the correct answer: stackoverflow.com/a/27767179/343679
-
Karthikeyan Ve over 8 years@Pratik Butani The solution worked for me. I would like to know the reason for getting the error?Could you please explain?
-
Pratik Butani over 8 yearsIts is problem in lollipop only. In that they are not uninstalling app for all user so we have to do that manually. I think.
-
nilsmagnus over 8 yearsThis 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.
-
yuval over 8 yearsIf 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 it -
The_Martian over 8 yearsThe error comes back as soon as I add the permissions again. My phone is Verizon Mottorola with Lollypop 5.1 :(
-
Pedro Teran over 8 yearsI 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 problem
-
JannGabriel about 8 yearsUsing ${applicationId} instead of static application id solved my problem!! Including when using Flavors!!!!
-
IgorGanapolsky about 8 yearsI don't find my app at the bottom of the list with NOT INSTALLED tag. What do you mean?
-
Andrew almost 8 yearsusing
${applicationId}
fixed the issue for me! -
Jonik over 7 years@yuval's comment is spot on and resolved this for me. Out of the many answer, this one best covers the issue: stackoverflow.com/a/36992939/56285
-
Vincent over 7 yearsHow does this adress the issue mentioned?
-
goemic over 7 yearsthis 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 apk
-
Tadej almost 7 yearsIn which file is this? -> Android manifest file in the "Properties" directory.
-
TheIT about 6 yearsIt 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.
-
Prateek Surana almost 6 yearsThanks, @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 instead
-
Ahmed Garhy almost 6 yearsthis should be marked as the correct answer .. thanks @Jackpile
-
Reaz Murshed over 4 yearsIt gave me
Failure [DELETE_FAILED_INTERNAL_ERROR]
. What might be the reason? -
CoolMind over 4 yearsThanks! I deleted both release and debug versions of the same application.
-
BobbyMick over 3 yearsThis worked perfectly for me when nothing else would. Thanks for sharing it.