Java Android 中的 INSTALL_FAILED_CONFLICTING_PROVIDER

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21271246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:47:53  来源:igfitidea点击:

INSTALL_FAILED_CONFLICTING_PROVIDER in Android

javaandroidmanifestandroid-contentprovider

提问by ghostrider

I am using an open-srouce code from Google for an app called MyTracks.

我正在将 Google 的开源代码用于名为 MyTracks 的应用程序。

I am getting this error when the original app is installed on the phone.

在手机上安装原始应用程序时出现此错误。

INSTALL_FAILED_CONFLICTING_PROVIDER

I know that this is because of the android:authoritiesin the Manifest.

我知道这是因为android:authorities在 Manifest 中。

here is the part of the Manifest:

这是清单的一部分:

<provider
android:name="com.google.android.apps.mytracks.content.MyTracksProvider"
android:authorities="com.google.android.maps.mytracks"
android:exported="true"
android:readPermission="com.google.android.apps.mytracks.READ_TRACK_DATA"
android:writePermission="com.google.android.apps.mytracks.WRITE_TRACK_DATA" />
<!-- Search suggestion provider -->
<provider
android:name="com.google.android.apps.mytracks.content.SearchEngineProvider"
android:authorities="com.google.android.maps.mytracks.search"
android:exported="false" />

So, my question is: I want to know whether this approach may solve the problem or not, because I am afraid of changing all the packages names and then have the whole app broken.

所以,我的问题是:我想知道这种方法是否可以解决问题,因为我害怕更改所有包名称,然后整个应用程序都会被破坏。

  1. The android :authoritiesvalue is the package name. The android:nameis the name of the class of that provider. Am I correct?
  1. android :authorities值是包名称。该android:name是类供应商的名称。我对么?

If I change the package name, to another one different than the com.google etx, and rename all the references/ imports of that package, should the problem go away?

如果我将包名称更改为不同于 com.google etx 的另一个名称,并重命名该包的所有引用/导入,问题是否会消失?

采纳答案by CommonsWare

The android :authorities value is the package name.

android :authorities 值是包名称。

In this case, it happensto be the package name. It simply has to be unique.

在这种情况下,它恰好是包名称。它必须是独一无二的。

The android:name is the name of the class of that provider

android:name 是该提供程序的类的名称

Correct.

正确的。

If I change the package name, to another one different than the com.google etx, and rename all the references/ imports of that package, should the problem go away?

如果我将包名称更改为不同于 com.google etx 的另一个名称,并重命名该包的所有引用/导入,问题是否会消失?

The package name has nothing to do with it. You may need to change that as well, though, for your app to be able to be installed alongside the regular, un-modified app.

包名与它无关。不过,您可能也需要更改它,以便您的应用程序能够与常规的、未修改的应用程序一起安装。

You need to have a unique value for android:authorities, and the code in your app that uses this ContentProviderneeds to use an appropriate Uri(content://whatever.you.change.the.authority.to/...).

您需要有一个唯一的 值android:authorities,并且您的应用程序中使用此值的代码ContentProvider需要使用适当的Uri( content://whatever.you.change.the.authority.to/...)。

回答by ban-geoengineering

I got this same error when I changed the package name in my app's manifest. This creates a conflict when you try to install the app again (with the new package name). The solution is to remove the old version of the app (that uses the old package name), then you'll be able to install the new version.

当我更改应用程序清单中的包名称时,我遇到了同样的错误。当您尝试再次安装应用程序(使用新的包名称)时,这会产生冲突。解决方案是删除旧版本的应用程序(使用旧包名称),然后您将能够安装新版本。

回答by Sourabh

just uninstall helloFacebooksample app from you device

只需从您的设备上卸载 helloFacebooksample 应用程序

回答by hkaraoglu

You maybe compile same library or including libraries. For example :

您可能编译相同的库或包含库。例如 :

compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'

Above code, google play services (first line ) includes all other services .

以上代码,谷歌播放服务(第一行)包括所有其他服务。

回答by DiscDev

If you are using Google Maps + Google Play Services inside a library project, you can encounter this error when you try to run an app that uses your library, while a different app that uses the same library is already installed on your device.

如果您在图书馆项目中使用 Google 地图 + Google Play 服务,当您尝试运行使用您图书馆的应用程序时可能会遇到此错误,而使用相同图书馆的其他应用程序已安装在您的设备上。

Fix:make sure that defaultConfig.applicationId is defined in android section of the build.gradlefile for each project using your library

修复:确保在build.gradle使用您的库的每个项目的文件的android 部分中定义了 defaultConfig.applicationId

android {
    defaultConfig.applicationId = "com.company.appname"
}

I would recommend using the package name of the specific app. With this fix, the provider names will no longer conflict, and your app will run as expected.

我建议使用特定应用程序的包名称。使用此修复程序,提供程序名称将不再冲突,您的应用程序将按预期运行。

Symptoms

症状

1.) Your users are seeing the dreaded "-505" install error when installing your app from the Play Store.

1.) 从 Play 商店安装您的应用程序时,您的用户会看到可怕的“-505”安装错误。

2.) You will see this error message when you try to install a second app that uses your library via Android Studio:

2.) 当您尝试通过 Android Studio 安装使用您的库的第二个应用程序时,您将看到此错误消息:

enter image description here

在此处输入图片说明

In your console, you will see a message like this:

在您的控制台中,您将看到如下消息:

Package couldn't be installed in /data/app/com.company.appname-1
com.android.server.pm.PackageManagerException: 
Can't install because provider name 
com.google.android.gms.measurement.google_measurement_service 
(in package com.company.appname) is already used by
com.company.otherInstalledAppName

The fix is to make sure that defaultConfig.applicationId is defined in android section of the build.gradlefile for each project using your library

修复是确保 defaultConfig.applicationId 在build.gradle文件的android 部分为每个使用您的库的项目定义

android {
    defaultConfig.applicationId = "com.company.appname"
}

More reading can be found here in the original bug report: Issue 784: Multiple apps using same authority provider name

更多阅读可以在原始错误报告中找到:问题 784:多个应用程序使用相同的权限提供程序名称

回答by Krupa

The gradle also needs to contain this

gradle 也需要包含这个

defaultConfig {
  applicationId "com.example.app"
}

I had left it out completely

我完全忽略了它

回答by NickUnuchek

if you use for ex facebook-sdk then for each app you need unique this line in manifest

如果您用于前 facebook-sdk,那么对于每个应用程序,您都需要在清单中使用唯一的这一行

<provider android:authorities="com.facebook.app.FacebookContentProviderxxxxxxxxxx"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="true"/>

xxxxxxxxxx - should be unique for each app, for facebook-sdk it's your facebook_id number

xxxxxxxxxx - 每个应用程序都应该是唯一的,对于 facebook-sdk,它是您的 facebook_id 号码

回答by NickUnuchek

may be your phone memory is full so please check it

可能是您的手机内存已满,请检查一下

回答by MobileMateo

CommonsWare has it right, however, there are more details that may help.

CommonsWare 是对的,但是,还有更多细节可能会有所帮助。

For me, there were two key parts of the solution. First I added $(applicationId) to Manifest provider entry:

对我来说,解决方案有两个关键部分。首先,我将 $(applicationId) 添加到 Manifest provider 条目:

        <provider
            tools:replace="android:authorities"
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.files"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/fileprovider" />
        </provider>

Second, when you switch Build Varients, and for me this is between 'debug' and 'release', you also need to Sync Project with Gradle Files. It was not enough to just Clean and Rebuild project.

其次,当您切换 Build Varients 时,对我来说这是在“调试”和“发布”之间,您还需要将项目与 Gradle 文件同步。仅仅清理和重建项目是不够的。

In Android Studio there are two tabs in the bottom of the AndroidManifest.xml page. The 'Text' tab you use to edit and the 'Merged Manifest' tab shows the resulting manifest after the build, and for me I can see it was injecting the applicationId properly into the android:authorities section of the provider.

在 Android Studio 中,AndroidManifest.xml 页面底部有两个选项卡。您用于编辑的“文本”选项卡和“合并清单”选项卡显示构建后的结果清单,对我而言,我可以看到它正在将 applicationId 正确注入提供程序的 android:authorities 部分。

回答by apurv thakkar

Just Uninstall the application from the device which you are trying to run and try to reinstallapplication again. The existing application is conflicting with the new one.

只需从您尝试运行的设备上卸载应用程序,然后再次尝试重新安装应用程序。现有应用程序与新应用程序冲突。