Android Facebook content provider authority
Asked Answered
S

4

23

I'm developing an app with (at least) two flavors having different package names - therefore actually two different apps as far as the android system is concerned. The app uses Facebook sharing, so I have the provider declared in the manifest:

<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="true"/>

This is done according to Facebook's instructions: https://developers.facebook.com/docs/sharing/android

This works fine with one app, but trying to install the second app on the same device fails with the error INSTALL_FAILED_CONFLICTING_PROVIDER. This is the only provider defined in the manifest so I'm pretty sure it's the problem. If I change the provider string to be something different it crashes when attempting to open a Facebook share dialog.

I've seen claims that it's possible to use the same Facebook app in multiple android apps, but can't find anything in Facebook's documentation about it. Has anybody done this, and how did you get around the provider authority problem? Thanks.

Spam answered 12/6, 2015 at 16:18 Comment(10)
If each flavor has a different applicationId, then you could do something like this: https://mcmap.net/q/458071/-using-applicationid-in-library-manifest and inject the correct applicationId into the provider's declaration in the manifest, since $(applicationId) actually returns the package name and not the applicationId you defined in gradleIntricacy
Finally getting back to this - I'm going to try it, but it seems like this will run into the same problem since the app ends up with the same authority string, just from the build process rather than directly in the manifest.Spam
You should maybe look into injecting the different values based on the applicationId at build-time. Here's actually an answer of mine from last week that should help you do it: https://mcmap.net/q/458071/-using-applicationid-in-library-manifestIntricacy
If I try to use a different value, the Facebook share functionality crashes the app. The problem is that Facebook apparently requires the same provider authority for each Facebook app, so I can't see how it's possible to use one Facebook app across multiple Android apps. If someone can tell me conclusively that it is not possible (preferably with supporting documentation) that would be an acceptable answer.Spam
It'd appear that the provider limitation will only allow you to have one app with sharing capabilities. You could have other android apps using the same Facebook app, but only one of them will be able to share linkable content. You'd have to make sure that only one of the apps actually exports the provider information to make sure the others don't conflict and fail to install.Intricacy
Yeah that's what I'm thinking, thanks.Spam
Hi @Spam I am running in the same problem and I have tried to remove from my manifest the facebook provider tag that you posted in your question and I noticed that now I can not only install all the product flavours that I have, but also fb sharing doesn't crash at all. I am using facebook version 4.6.0. I was curious to know if also in your app facebook works without the provider and if you know why we actually need this provider at all.Rathbone
If you read this you will see that you do not need the FacebookContentProvider unless you are attaching images.Moneymaking
Interesting, thank you @ThomasClowes!Spam
See #33295617Lamonicalamont
P
14

I was able to solve this by having separate manifests for my debug and release flavors and in my debug flavor manifest, I added the snippet for the provider but set the exported value to false. In my release flavor manifest, I have the original provider snippet with exported set to true.

After I did this, I no longer got the INSTALL_FAILED_CONFLICTING_PROVIDER error.

<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>
Propriety answered 23/10, 2015 at 2:23 Comment(8)
Thank you, I'll see if I can try that.Spam
@Spam So did u able to solve this issue please post a brief answer that how u solved this issue. Creating multiple manifest files not looking a wise solution.Doeskin
@Doeskin Why? Android Studio will merge the manifests into a single file at build time. developer.android.com/tools/building/manifest-merge.htmlSpam
@Spam when I am trying with multiple falvours than in other flavour I am not able to get email id but other details are coming like name and id. what could be the reason, My all flavours are production version so I have created multiple manifest with different app id for every package name.Doeskin
I don't know, you should probably ask a new question. Feel free to link to it here.Spam
you can use: com.facebook.app.FacebookContentProvider${applicationId} don't worry about applicationId.Deviate
This works in this case for debug/release flavors. But not if I want to actually release multiple apps with the same facebook app id. I think it's not possible to have the provider set up in more than one app if you want to use the same app id.Dike
This seems promising, but android:exported="false" seems to make no difference. I get INSTALL_FAILED_CONFLICTING_PROVIDER as long as I try to use the same FB provider id in different variants.Carreno
F
17

One of the possible solutions I have found is the one described here

http://gradlewhy.ghost.io/overcoming-install-failed-conflicting-provider/

I am already using this for (debug/release variants) android.support.v4.content.FileProvider and as far I have tested also works for com.facebook.app.FacebookContentProvider.

Just add into apps build.gradle

    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'

        resValue "string", "fb_provider_id", "com.facebook.app.FacebookContentProvider{app_id_1}"
    }

    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        resValue "string", "fb_provider_id", "com.facebook.app.FacebookContentProvider{app_id_2}"
    }

and then in the AndroidManifest

<provider android:authorities="@string/fb_provider_id"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true"/>
Footplate answered 4/4, 2017 at 19:59 Comment(3)
thank you @Footplate , I followed your answer, thank u.Plymouth
I'm glad it helped you :)Footplate
This is realy help full @borko!Detrain
P
14

I was able to solve this by having separate manifests for my debug and release flavors and in my debug flavor manifest, I added the snippet for the provider but set the exported value to false. In my release flavor manifest, I have the original provider snippet with exported set to true.

After I did this, I no longer got the INSTALL_FAILED_CONFLICTING_PROVIDER error.

<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>
Propriety answered 23/10, 2015 at 2:23 Comment(8)
Thank you, I'll see if I can try that.Spam
@Spam So did u able to solve this issue please post a brief answer that how u solved this issue. Creating multiple manifest files not looking a wise solution.Doeskin
@Doeskin Why? Android Studio will merge the manifests into a single file at build time. developer.android.com/tools/building/manifest-merge.htmlSpam
@Spam when I am trying with multiple falvours than in other flavour I am not able to get email id but other details are coming like name and id. what could be the reason, My all flavours are production version so I have created multiple manifest with different app id for every package name.Doeskin
I don't know, you should probably ask a new question. Feel free to link to it here.Spam
you can use: com.facebook.app.FacebookContentProvider${applicationId} don't worry about applicationId.Deviate
This works in this case for debug/release flavors. But not if I want to actually release multiple apps with the same facebook app id. I think it's not possible to have the provider set up in more than one app if you want to use the same app id.Dike
This seems promising, but android:exported="false" seems to make no difference. I get INSTALL_FAILED_CONFLICTING_PROVIDER as long as I try to use the same FB provider id in different variants.Carreno
B
3
<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>

exported can be "true"

Bruce answered 1/11, 2015 at 10:0 Comment(1)
What for "exported can be "true" true or false"?Cockleshell
C
2

If your have one project and multiple flavors(means: multiple apps with minor tweaks) like me, you can

1.create multiple facebook app (from https://developers.facebook.com/apps/)

2.add codes for correspoding flavor

3.add facebook_app_id string value in the corresponding flavor's folder.

Example:

app/build.gradle

...
flavorDimensions "regular"

productFlavors {
    flavour_name {
        dimension "regular"
        resValue "string", "authority", "com.facebook.app.FacebookContentProvider123456789"
    }

app/src/main/AndroidManifest.xml

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

<provider android:authorities="@string/authority"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true" />

app/src/flavour_name/res/values/string.xml

<string name="facebook_app_id" translatable="false">123456789</string>
Constanceconstancia answered 8/9, 2018 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.