INSTALL_FAILED_DUPLICATE_PERMISSION ... C2D_MESSAGE

Nul*_*ion 176 android android-notifications google-cloud-messaging android-5.0-lollipop

我在我的应用中使用Google通知,直到现在我在清单中完成了以下操作:

<!-- 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 -->
Run Code Online (Sandbox Code Playgroud)

它完美运行,直到我将Nexus 7更新为Android 5.0.
现在,当我尝试使用Eclipse在此设备中安装应用程序时,出现此错误:

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

我不明白有什么问题......它在Android 5.0之前完美运行.
我知道,我使用C2D_MESSAGE的两条线,permissionuses-permission但我已经复制从原来的谷歌GCM指南,代码,因此它必须是罚款.

Pra*_*ani 226

我找到了一个适合我的解决方案.

在我的设备(Nexus 7)Android 5.0中.棒棒糖我按照这些步骤.

卸载应用程序后您将App NameDownloaded选项卡的应用程序列表下找到.

  • 前往设置
  • 应用
  • 在列表的底部,您将找到YourApp"未安装"标签
  • 打开
  • 单击OptionMenu并选择"为所有用户卸载"

在此过程之后,我成功安装了新应用程序并且运行良好.

  • 我用nexus 9安装了android 5.0.1,我看不到我的应用程序带有"noto installed"标签 (6认同)
  • 我在列表底部找不到带有 **未安装** 标签的应用程序。你是什​​么意思? (2认同)

小智 135

去掉

<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
<permission
    android:name="${applicationId}.permission.C2D_MESSAGE"
    android:protectionLevel="signature"/>
Run Code Online (Sandbox Code Playgroud)

运行应用程序...然后再次添加权限并运行应用程序.

准备!.

  • 当您尝试在同一设备上安装应用程序的调试版和发行版时,通常会出现此问题.使用此解决方案,您可以轻松完成.我不知道你可以在清单中使用变量.给予好评! (30认同)
  • 如果应用程序已在生产中,则此答案无效.我不能指望我的应用程序的用户在没有权限的情况下下载新版本,然后再次安装具有权限的新版本. (4认同)
  • 如果发生这种情况是因为您的应用程序的调试版和发行版具有不同的名称,那么卸载不需要它可以工作:您只需要使用`$ {applicationId}`而不是硬编码它 (4认同)
  • 使用 ${applicationId} 而不是静态应用程序 ID 解决了我的问题!!包括使用 Flavors 时!!!! (2认同)

x-c*_*ode 48

我在Android-21上的自定义签名权限遇到了同样的问题,并通过确保我完全卸载来解决它.

这是在以下情况下发生的边缘情况:

  1. 应用程序使用签名级别安全性定义自定义权限
  2. 您尝试使用使用其他密钥签名的版本更新已安装的应用程序
  3. 测试设备运行Android 21或更高版本,支持多个用户

命令行示例

这是一个命令行脚本,演示了该问题以及如何解决它.此时安装了调试版本,我正在尝试安装使用发布密钥签名的生产版本:

# 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]# 
Run Code Online (Sandbox Code Playgroud)

Eclipse示例

向相反的方向发展(尝试在安装了发布版本时从Eclipse安装调试版本),我得到以下对话框:

Eclipse重新安装对话框

如果您此时只回答"是",则安装将成功.

设备示例

正如另一个答案中所指出的,您还可以转到设备设置中的应用信息页面,单击溢出菜单,然后选择"为所有用户卸载"以防止出现此错误.


Jac*_*ile 33

我已经解决了这个问题,而不必首先卸载备用apk(多么痛苦,对吧?).要成功安装apk的调试版和发行版,只需在AndroidManifest.xml中使用gradle的内置$ {applicationId}占位符,即在编译时修改权限'android:name值.

build.gradle文件片段:

buildTypes {
    debug {
        applicationIdSuffix ".debug"
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

AndroidStudio.xml文件片段:

<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
<permission
    android:name="${applicationId}.permission.C2D_MESSAGE"
    android:protectionLevel="signature"/>
Run Code Online (Sandbox Code Playgroud)

您可以使用apk检查修改后的AndroidManifest.xml文件,aapt l -a app-debug.apk以确保正确应用了占位符.如果您使用各种产品口味,我相信您可以应用此方法的变体来满足您的需求.


Dav*_*vid 26

从清单文件中删除包名称的任何"硬编码"引用.

(即使您不使用,这是最佳做法productFlavors)

例如,如果您的清单包含:

<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"/>
Run Code Online (Sandbox Code Playgroud)

将其更改为:

<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"/>
Run Code Online (Sandbox Code Playgroud)

然后,在您的模块gradle文件中,设置相关的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
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以按照本教程获取更多信息

  • 使用```$ {applicationId}```为我解决了这个问题! (2认同)

Giu*_*ppe 18

尝试使用adb卸载应用:

adb uninstall com.yourpackage
Run Code Online (Sandbox Code Playgroud)


Pre*_*Rao 17

在给出此错误时,它会清楚地提及应用程序的程序包名称,因为该权限被拒绝.只是卸载应用程序将无法解决问题.为了解决问题,我们需要执行以下步骤:

  1. 前往设置
  2. 去应用程序
  3. 转到下载的应用列表
  4. 您可以在列表中看到已卸载的应用程序
  5. 单击应用程序,转到更多选项
  6. 单击卸载以查看所有用户选项

问题解决了:D


Jor*_*sys 8

在OS 5.0中安装应用程序我得到以下消息:

INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.myapp.permission.C2D_MESSAGE pkg=com.myapp
Run Code Online (Sandbox Code Playgroud)

没有重复的软件包,我们可以解决此问题,手动卸载旧应用程序或使用adb:

adb uninstall com.yourpackage


The*_*ian 5

以上都不适合我。我的应用程序在 Lollipop 之前运行良好。但是当我在 Lollipop 上测试时,出现了上述错误。它拒绝安装。我没有安装任何以前的版本,所以上述所有解决方案对我来说都是无效的。但是多亏了这个 SO 解决方案,它现在运行良好。就像大多数开发人员一样,我遵循了 Google 的误导性教程,并通过复制和粘贴添加了权限,如下所示:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.google.android.permission.C2D_MESSAGE" 
            android:protectionLevel="signature" />
Run Code Online (Sandbox Code Playgroud)

这适用于旧版本 < Lollipop。所以现在我改为:

<uses-permission android:name="com.mycompany.myappname.c2dm.permission.RECEIVE" />
<permission android:name="com.mycompany.myappname.permission.C2D_MESSAGE" 
            android:protectionLevel="signature" />
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

105618 次

最近记录:

6 年,10 月 前