今天在android手机上安装惠惠购物助手最新版(3.8.2)的时候,提示安装失败。期初,还以为自己手机有问题,但是安装了几个软件都正常之后判断原因出在app上。
调试错误信息
打开android studio,看到如下的错误信息:
06-12 14:27:06.281 434-434/? E/installd: Couldn't opendir /data/data/com.youdao.huihui.deals: No such file or directory
06-12 14:27:06.281 1401-1505/? W/PackageManager: Package couldn't be installed in /data/app/com.youdao.huihui.deals-1
com.android.server.pm.PackageManagerException: Can't install because provider name com.google.android.gms.measurement.google_measurement_service (in package com.youdao.huihui.deals) is already used by com.wego.android
at com.android.server.pm.PackageManagerService.scanPackageDirtyLI(PackageManagerService.java:5695)
at com.android.server.pm.PackageManagerService.scanPackageLI(PackageManagerService.java:5360)
at com.android.server.pm.PackageManagerService.installNewPackageLI(PackageManagerService.java:10367)
at com.android.server.pm.PackageManagerService.installPackageLI(PackageManagerService.java:10912)
at com.android.server.pm.PackageManagerService.access$2300(PackageManagerService.java:242)
at com.android.server.pm.PackageManagerService$6.run(PackageManagerService.java:8817)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
错误原因
错误原因在于provider的authorities不唯一,产生此现象的原因在于:
Setting android.defaultConfig.applicationId in your gradle file is something that is expected to be set in Android projects. This is automatically added when you create a new Android project in Android Studio.
However when applicationId isn't present in the project gradle the play-services-measurement AAR package in its AndroidManifest.xml gets defaulted in. This creates a silent issue for the app developer as their is no warnings or errors when the app builds. Only after another app that was build the same way is also installed on the device is the issue known as the OP noted with the INSTALL_FAILED_CONFLICTING_PROVIDER error.
The fix is adding android.defaultConfig.applicationId to your app's gradle file as others have noted however, the play-services-measurement AAR or the build tools should be changed to throw an error if this is missing.
解决方案
解决方案其实有两个
- 卸载与其冲突的wego(com.wego.android)
- 惠惠购物助手修复它的bug
卸载与其冲突的wego(com.wego.android)
显然这不是长久之计
惠惠购物助手修复它的bug
这是网易app开发同学的事情,不过修复起来很简单
在gradle里边配置一下即可
android {
defaultConfig.applicationId = "my.package.id"
}