8

I have my facebook application id on my gradle properties with :

FACEBOOK_APPLICATION_ID="XXXXXXXXXXXXXXX"

and I set in my defaultConfig :

manifestPlaceholders = [facebookAppId: FACEBOOK_APPLICATION_ID]

then, I want to use this in my manifest with :

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="${facebookAppId}" />

but it doesn't work. The only things working are to set my faceboook id in a string :

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

or to put this directly with :

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="\ XXXXXXXXXXXXXX" />

but I must set my facebook id in my gradle properties. What is the right way to do this ?

Thanks.

Magnas
  • 869
  • 1
  • 5
  • 18
  • Tried it as well and it didn't work for me. Even on android dev site they explicitly wrote value instead of getting value from a gradle variable: `manifestPlaceholders = [facebookAppId: "facebook-id-12345678"]` https://developer.android.com/studio/build/manifest-build-variables – Kirill Karmazin May 10 '19 at 12:06

1 Answers1

11

I am new on Gradle, but if I understood your questions I would suggest using something like that:

buildTypes {
    debug {
        // ...
    }
    release {
        // ...
        resValue "string", "facebook_application_id", "XXXXXXXXXXXXXXXXX"
    }
}

Then, at your release build, for this example, you can use it as

android:value="@string/facebook_application_id"

Or even

R.string.facebook_application_id
Eduardo
  • 4,282
  • 2
  • 49
  • 63
  • 1
    It works perfectly, thanks ! it may be useful so this link explain this http://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java – Magnas Nov 19 '15 at 16:14
  • Nice it was what you were looking for. If you can mark the answer as the correct one, that helps me :-) – Eduardo Nov 19 '15 at 16:17
  • while it works, it is not secure. Strings can be easily extracted from an apk. See https://rammic.github.io/2015/07/28/hiding-secrets-in-android-apps/ – YTerle Aug 04 '21 at 13:06