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.

10
  • If each flavor has a different applicationId, then you could do something like this: 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, 2015 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, 2015 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: stackoverflow.com/a/30791242/1426565
    – Cruceo
    Jun 15, 2015 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, 2015 at 18:28
  • 1
    If you read this you will see that you do not need the FacebookContentProvider unless you are attaching images. Feb 4, 2016 at 12:21

4 Answers 4

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"/>
2
  • thank you @borko , I followed your answer, thank u. Apr 29, 2019 at 20:21
  • 1
    I'm glad it helped you :)
    – borko
    Apr 30, 2019 at 6:12
13

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"/>
8
  • Thank you, I'll see if I can try that.
    – nasch
    Oct 24, 2015 at 0: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 2, 2016 at 15:59
  • 1
    @Min2 Why? Android Studio will merge the manifests into a single file at build time. developer.android.com/tools/building/manifest-merge.html
    – nasch
    Jan 3, 2016 at 2: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, 2016 at 11:20
  • I don't know, you should probably ask a new question. Feel free to link to it here.
    – nasch
    Apr 22, 2016 at 15:38
3
<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>

exported can be "true"

1
  • What for "exported can be "true" true or false"?
    – Jorgesys
    Jan 13, 2022 at 21:29
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>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.