Android Facebook content provider authority

nasch picture nasch · Jun 12, 2015 · Viewed 16.4k times · Source

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.

Answer

borko picture borko · Apr 4, 2017

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"/>