我在我的应用中使用Google通知,直到现在我在清单中完成了以下操作:
它完美运行,直到我将Nexus 7更新为Android 5.0.
现在,当我尝试使用Eclipse在此设备中安装应用程序时,出现此错误:
INSTALL_FAILED_DUPLICATE_PERMISSION perm = com.myapp.permission.C2D_MESSAGE pkg = com.myapp
我不明白有什么问题......它在Android 5.0之前完美运行.
我知道,我使用C2D_MESSAGE
的两条线,permission
并uses-permission
但我已经复制从原来的谷歌GCM指南,代码,因此它必须是罚款.
我已经解决了这个问题,而不必首先卸载备用apk(多么痛苦,对吧?).要成功安装apk的调试版和发行版,只需在AndroidManifest.xml中使用gradle的内置$ {applicationId}占位符,即在编译时修改权限'android:name值.
build.gradle文件片段:
buildTypes { debug { applicationIdSuffix ".debug" ... } }
AndroidStudio.xml文件片段:
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
您可以使用apk检查修改后的AndroidManifest.xml文件,aapt l -a app-debug.apk
以确保正确应用了占位符.如果您使用各种产品口味,我相信您可以应用此方法的变体来满足您的需求.
从清单文件中删除包名称的任何"硬编码"引用.
(即使您不使用,这是最佳做法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"/>
将其更改为:
<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"/>
然后,在您的模块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 } }
您可以按照本教程获取更多信息
在给出此错误时,它会清楚地提及应用程序的程序包名称,因为该权限被拒绝.只是卸载应用程序将无法解决问题.为了解决问题,我们需要执行以下步骤:
前往设置
去应用程序
转到下载的应用列表
您可以在列表中看到已卸载的应用程序
单击应用程序,转到更多选项
单击卸载以查看所有用户选项
问题解决了:D
我找到了一个适合我的解决方案.
在我的设备(Nexus 7)Android 5.0中.棒棒糖我按照这些步骤.
卸载应用程序后您将App Name
在Downloaded
选项卡的应用程序列表下找到.
前往设置
应用
在列表的底部,您将找到YourApp
"未安装"标签
打开
单击OptionMenu
并选择"为所有用户卸载"
在此过程之后,我成功安装了新应用程序并且运行良好.
去掉
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
运行应用程序...然后再次添加权限并运行应用程序.
准备!.
我在Android-21上的自定义签名权限遇到了同样的问题,并通过确保我完全卸载来解决它.
这是在以下情况下发生的边缘情况:
应用程序使用签名级别安全性定义自定义权限
您尝试使用使用其他密钥签名的版本更新已安装的应用程序
测试设备运行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]#
向相反的方向发展(尝试在安装了发布版本时从Eclipse安装调试版本),我得到以下对话框:
如果您此时只回答"是",则安装将成功.
正如另一个答案中所指出的,您还可以转到设备设置中的应用信息页面,单击溢出菜单,然后选择"为所有用户卸载"以防止出现此错误.
在OS 5.0中安装应用程序我得到以下消息:
INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.myapp.permission.C2D_MESSAGE pkg=com.myapp
没有重复的软件包,我们可以解决此问题,手动卸载旧应用程序或使用adb:
adb uninstall com.yourpackage