问题描述:

I'm facing a strange problem with android studio. I have two Android app that uses facebook sdk with same facebook Application for login and share pictures. With new api, it's necessary to declare inside manifest this:

<provider android:authorities="com.facebook.app.FacebookContentProvider[app_id]"

android:name="com.facebook.FacebookContentProvider"

android:exported="true"/>

Now if one of that app is already installed on device and i try to install the second one, i obtain this error on Android studio:

INSTALL_FAILED_CONFLICTING_PROVIDER

It's necessary a problem of facebook provider, that is the only

element inside my app.

So, in this way my two apps couldn't be installed at the same time on the same device?

I would like if there's a way for use same provider and avoid that error.

网友答案:

This is an old question I know, but there wasn't a clear-cut answer to this that I could find. Thought I'd post how I've done it.

You can't have two different apps (or the same app using two different application ids) using the same Facebook App Id. This breaks the ContentProvider stuff. You need to create a test app under your main app on the Facebook developer area. Then take the new app ID from there and keep it handy.

Next, in your build.gradle, add (or append) the following entry to your defaultConfig block.

    manifestPlaceholders = [ facebook_app_id:"" ]

Then in your debug config add:

    manifestPlaceholders = [ facebook_app_id:"<the_debug_app_id_you_kept_handy>"]

Then in your release config add:

    manifestPlaceholders = [ facebook_app_id:"<the_original_app_id_you_had>" ]

Now, change your AndroidManifest.xml. Change:

    <provider android:authorities="com.facebook.app.FacebookContentProvider<original_app_id>"

to:

    <provider android:authorities="com.facebook.app.FacebookContentProvider${facebook_app_id}"

and, change:

    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="<original_app_id>"/>

to:

    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="${facebook_app_id}"/>

That should do it. What you've done is add a placeholder to the manifest. Essentially it's a variable, that you can then set your gradle build to populate its value with different things based on the build type or flavor.

网友答案:

So, in this way my two apps couldn't be installed at the same time on the same device?

Correct.

I would like if there's a way for use same provider and avoid that error.

The following has nothing to do with Facebook's SDK, but deals only with Android and its limits. Facebook's SDK may impose new and exciting limits.

In theory, you could say that App A has the <provider> and App B uses the provider from App A. This implies that App B cannot be used on its own. When the user runs the app, you would have to check to see if App A is installed and force the user to install it in order to be able to use App B. This may cause some amount of user angst. If you want both App A and App B to be usable individually, that is fine, but then both will have to have the <provider> and then they cannot both be installed at the same time.

Ideally, you would solve this by having both <provider> elements be disabled (android:enabled="false") at the outset. Then, whoever runs first would elect itself to be the one offering the provider for that device, at which point it would enable the provider. Alas, due to an Android bug/limitation, this will not solve the problem, as you will not be able to have both installed at the same time anyway.

I tend to agree with Rajan Bhavsar's comment. Either you need to have one Android app for your one Facebook app ID, or you need two Facebook app IDs for your two Android apps.

网友答案:

As far as I can see there is no requirement on the name for the android:autorities in the respective provider node (https://developer.android.com/guide/topics/manifest/provider-element.html), so you could make the URI unique by injecting the applicationId:

android:authorities="${applicationId}.com.facebook.app.FacebookContentProvider[app_id]
网友答案:

So you can change the provider name from one of your app. Use App name Inst ed of App_id.

相关阅读:
Top