others-how to solve `Error: INSTALL_FAILED_CONFLICTING_PROVIDER` when trying to install an app in the phone?

1. Problem

When trying to install an app in a phone, we got this error:

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_CONFLICTING_PROVIDER

List of apks:
[0] '/Users/bswen/myproject3/app/app/build/outputs/apk/proCn/debug/app-proCn-debug.apk'
Installation failed due to: 'Failed to commit install session 854235070 with command cmd package install-commit 854235070. Error: INSTALL_FAILED_CONFLICTING_PROVIDER: Scanning Failed.: Can't install because provider name com.app.app (in package com.bswen.app3) is already used by com.app.app'
Retry
Failed to launch an application on all devices

The core error message is:

Error: INSTALL_FAILED_CONFLICTING_PROVIDER: Scanning Failed.: Can't install because provider name com.app.app (in package com.bswen.app3) is already used by com.app.app'

The configuration file: AndroidManifest.xml:

<provider
    android:name=".MyContentProvider"
    android:enabled="true"
    android:authorities="com.app.app;com.app.apps;com.app.app3;com.app.appxm;com.bswen.app3"
    android:exported="false"
    android:grantUriPermissions="true" />



2. Solution

2.1 The reason of this problem

Android manifest providers defined in main use all the package names. We should only use one package name for one build variant.

A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object

And android:authorities is a list of one or more URI authorities that identify data offered by the content provider. Multiple authorities are listed by separating their names with a semicolon.

2.2 The working solution for me

Change the provider authorities to use only the current package name:

<provider
    android:name=".MyContentProvider"
    android:enabled="true"
    android:authorities="com.bswen.app3"
    android:exported="false"
    android:grantUriPermissions="true" />

In other build variant, define its own and override the default:

<provider
    tools:node="replace"
    android:name=".MyContentProvider"
    android:enabled="true"
    android:authorities="com.app.app3"
    android:exported="false"
    android:grantUriPermissions="true" />

You can get more information from here.



3. Summary

In this post, I demonstrated how to solve the Error: INSTALL_FAILED_CONFLICTING_PROVIDER when trying to install an app in the phone. The key point is to change the authorities in our <Provider> in AndroidManifest.xml.That’s it, thanks for your reading.

-->