22

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.

nasch
  • 5,330
  • 6
  • 31
  • 52
  • If each flavor has a different applicationId, then you could do something like this: http://stackoverflow.com/a/30791242/1426565 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 gradle – Cruceo Jun 12 '15 at 17:37
  • 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. – nasch Jun 15 '15 at 18:01
  • 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: http://stackoverflow.com/a/30791242/1426565 – Cruceo Jun 15 '15 at 18:05
  • 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. – nasch Jun 15 '15 at 18:28
  • 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. – Cruceo Jun 15 '15 at 19:13
  • Yeah that's what I'm thinking, thanks. – nasch Jun 15 '15 at 19:30
  • Hi @nasch 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. – Antonio Cappiello Nov 27 '15 at 14:17
  • 1
    If you read [this](https://developers.facebook.com/docs/reference/android/current/class/FacebookContentProvider/) you will see that you do not need the FacebookContentProvider unless you are attaching images. – Thomas Clowes Feb 04 '16 at 12:21
  • Interesting, thank you @ThomasClowes! – nasch Feb 04 '16 at 15:10
  • See http://stackoverflow.com/questions/33295117/set-a-global-variable-in-gradle-that-can-use-in-manifest-file – Denny Weinberg Oct 02 '16 at 11:16

4 Answers4

15

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"/>
borko
  • 151
  • 1
  • 6
12

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"/>
approxiblue
  • 6,982
  • 16
  • 51
  • 59
jkunzika
  • 164
  • 2
  • 8
  • Thank you, I'll see if I can try that. – nasch Oct 24 '15 at 00:46
  • @nasch 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. – Min2 Jan 02 '16 at 15:59
  • 1
    @Min2 Why? Android Studio will merge the manifests into a single file at build time. https://developer.android.com/tools/building/manifest-merge.html – nasch Jan 03 '16 at 02:38
  • @nasch 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. – Min2 Apr 22 '16 at 11:20
  • I don't know, you should probably ask a new question. Feel free to link to it here. – nasch Apr 22 '16 at 15:38
  • you can use: `com.facebook.app.FacebookContentProvider${applicationId}` don't worry about `applicationId`. – vuhung3990 Dec 14 '17 at 07:19
  • 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. – Day Jun 19 '18 at 08:19
  • 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. – Jonik Nov 11 '19 at 15:20
3
<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>

exported can be "true"

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>
touhid udoy
  • 4,005
  • 2
  • 18
  • 31