I implemented facebook login and now in the manifest I use 2 values ​​for meta-data one for release and one for debag

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

depending on the situation, I keep one commented out the other open, so how can I do this so that these values ​​are taken from the code?

I would then put the flag and not bother with switching these keys

Thank!

    2 answers 2

    create the following files in directories

     src > release > res > values > strings.xml src > debug > res > values > strings.xml 

    and in both files you put the same string

     <string name="facebook_app_id" translatable="false">yourId</string> 
    • if something is incomprehensible I can explain in more detail - Maxim Kuznetsov
    • I do not have the release and debug folders ... - Aleksey Timoshchenko
    • just create them in the src folder - Maxim Kuznetsov
    • And the res folder which is originally there and leave it? Just next to it create 2 new release and debug branches and add up your values ​​in them? - Aleksey Timoshchenko
    • yes, that's right, just 2 new release and debug branches and add up your values ​​in them - Maxim Kuznetsov

    You can change the required value depending on build options.

    In AndroidManifest.xml, type:

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

    And in build.gradle:

     release { ... resValue "string", "facebook_app_id", "value release" } debug { ... resValue "string", "facebook_app_id", "value debug" } 

    Similar can be realized also with the help of product flavors.

    And there is such a thing as Manifest Merger . Here it is not needed, but you can read for a general understanding, perhaps it will be needed in the future.

    • This method is good if there are few such strings, otherwise it will clutter up the whole code - Maxim Kuznetsov
    • @MaximKuznetsov, I give an answer on a specific question. As you can see, there is only one resource in this question. - post_zeew Nov.
    • I do not criticize your answer, it is good, I just commented on the understanding of those who will use this option. - Maxim Kuznetsov