Fail to install Apps on mobile running Android 5.0

最近遇到个比较奇怪的问题,就是应用在Android5.0的机器上安装失败,经过一系列搜索也没有找到原因。

I came into a rare problem these days, that is I got a FAIL when install my app on mobile running Android 5.0. That cost a lot of my time.

一个意外机会,有人提到是权限问题,安装失败是因为那台机器上安装了相同权限的应用。后来才查到,是因为Android5.0更新了权限管理机制,不再允许同一台设备上安装两个声明了相同自定义权限的应用(5.0以前是允许的)。如果使用 adb install xxx.apk 安装,会报这个错误:

INSTALL_FAILED_DUPLICATE_PERMISSION

After got somebody’s advice that the reason of failure may be the declaration of a same permission, I found that Android 5.0 has change the mechanism of management of permission. Due to that change, installation of 2 or more apps of custom permission with same name is not allowed (it is before that). When install by command like “adb install xxx.apk” you will get error report like this:

INSTALL_FAILED_DUPLICATE_PERMISSION
权限冲突的情况出现在使用了第三方library或SDK的情况下是比较常见的。所以如果使用了自定义权限,一定要注意做唯一性处理,常见的做法就是在自定义权限中增加自己应用的包名

However, this situation can be met easily when using 3rd-library or other SDK. So it is necessary to make sure that custom permissions declared in your app all have a unique name. A common approach is to append your app’s package name to those custom permissions.