8

I'm building an Android app with multiple productFlavors, and using Facebook SDK v4.1 for login and sharing contents. The problem is that when I try to install an app on a device which already has the same app installed (but different flavor), it raises an error. It doesn't allow me to install the second app unless I uninstall the existing one.

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

According to this document, the android:authorities should be unique and I should have multiple auths to accomplish what I want to do. However, I can't have multiple Facebook AppIds, and was wondering if there's better way to solve this problem. Thanks in advance to anyone who can help me!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Nari Kim Shin
  • 2,459
  • 1
  • 25
  • 33
  • 2
    `android:authorities="com.facebook.app.FacebookContentProvider{my_app_id}"` needs to be unique. It seems that another app having same authorities. Read at http://stackoverflow.com/questions/21271246/install-failed-conflicting-provider-in-android – Pankaj Kumar Jun 09 '15 at 05:55
  • 1
    @PankajKumar Please read my question carefully. – Nari Kim Shin Jun 09 '15 at 20:20
  • do u have any workaround for this problem now? – Wayne Dec 07 '15 at 12:27
  • 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:15

3 Answers3

7

Try below :

Manifest

<provider android:authorities="com.facebook.app.FacebookContentProvider${facebookId}"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true" />
<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="fb${facebookId}"/>

Gradle

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.your.package"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        manifestPlaceholders = [facebookId:"123456789"]
    }

    productFlavors {
    debug {
        applicationIdSuffix ".debug"
        manifestPlaceholders = [facebookId:"1234"]
    }
    release {
        applicationIdSuffix ".pro"
        manifestPlaceholders = [facebookId:"123456789"]
    }
}
Jaewon Kim
  • 71
  • 1
  • 4
  • 2
    Great answer, one question, why you need "fb" before fb${facebookId} ? – AndroidRuntimeException Sep 20 '17 at 13:42
  • 2
    what a trick! without 'fb' before ${facebookId} app crash with "invalid app id' message, I think it is converted to number, and add prefix 'fb' can prevent this? – Phong Nguyen Jun 19 '18 at 02:21
  • @AndroidRuntimeException [See Android Facebook source code](https://github.com/facebook/facebook-android-sdk/blob/1cafb982455f10fa4b7cc5e5374627a3efff49d7/facebook-core/src/main/java/com/facebook/FacebookSdk.java#L758) – Jaewon Kim Oct 23 '19 at 08:45
-1

You can use this:

Manifest

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

Gradle

productFlavors {
    flavor1 {
        applicationId "com.id.flavor1"
        versionCode 1
        versionName "1.0.0"
        resValue "string", "facebook_app_authority", "com.facebook.app.FacebookContentProvider0000000000000000"
    }
    flavor2 {
        applicationId "com.id.flavor2"
        versionCode 1
        versionName "1.0.0"
        resValue "string", "facebook_app_authority", "com.facebook.app.FacebookContentProvider0000000000000001"
    }
}

Replace 0000000000000000 to your App id

evgen shein
  • 81
  • 1
  • 2
  • 7
-7
<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="true"/>