React-native-config: [Android] Possible to use env vars in strings.xml for style/item ?

Created on 29 Sep 2016  路  10Comments  路  Source: luggit/react-native-config

App works fine when using env vars in AndroidManifest.xml but crashes when using env vars inside strings.xml

Edit: Basically my question is related to react-native-facebook-account-kit
I want to fetch following info from .env

<style name="LoginThemeYellow" parent="Theme.AccountKit">
    <item name="com_accountkit_primary_color">#f4bf56</item>
    <item name="com_accountkit_primary_text_color">@android:color/white</item>
    <item name="com_accountkit_secondary_text_color">#44566b</item>
    <item name="com_accountkit_status_bar_color">#ed9d00</item>

    <item name="com_accountkit_input_accent_color">?attr/com_accountkit_primary_color</item>
    <item name="com_accountkit_input_border_color">?attr/com_accountkit_primary_color</item>
</style>

Most helpful comment

@joncursi edit strings.xml like this

<string name="facebook_app_id">@string/FACEBOOK_APP_ID</string>

Note: FACEBOOK_APP_ID should be present in .env and if you are using different files for different environment (eg. staging, production) then in them too.

All 10 comments

This would be great. Any hints on how to implement this? I could give it a try.

Its working. Tested for react-native-facebook-login!

@prtkkmrsngh how'd you get it to work? I'm trying to do the same for react-native-facebook-login

I'm trying to do this in a dynamic way using this package:

  <string name="facebook_app_id">appIDhere</string>

@joncursi edit strings.xml like this

<string name="facebook_app_id">@string/FACEBOOK_APP_ID</string>

Note: FACEBOOK_APP_ID should be present in .env and if you are using different files for different environment (eg. staging, production) then in them too.

This is working on my computer but is not working on Bitrise build system

String.xml

<resources>
    <string name="facebook_app_id">@string/FACEBOOK_APP_ID</string>
    <string name="fb_login_protocol_scheme">@string/FACEBOOK_LOGIN_PROTOCOL_SCHEME</string>
</resources>

I have aunique .env file

FACEBOOK_APP_ID=00000001
FACEBOOK_LOGIN_PROTOCOL_SCHEME=fb00000001
:app:processReleaseResources/Users/vagrant/git/android/app/build/intermediates/res/merged/release/values/values.xml:923:36-59:  
AAPT: No resource found that matches the given
 name (at 'facebook_app_id' with value '@string/FACEBOOK_APP_ID').

Does anybody here use a build system and had similar problems ?

Same problem here @alfonsodev
Locally it's no issue, but on a CI/CD environment (budydbuild in my case) it does not work.

Did you find any solution?

@fforres Yes, in my particular case the problem was that
on the build steps I'm moving the folder after cloning it,
but mv command wasn't copying hidden files by default,
so the .env file didn't get copied and therefore the issue.
The solution was to run shopt -s dotglob before mv command so that .env gets copied over with the src files.
I hope it helps!

Same problem here.Any update?

Any news on that?

Was this page helpful?
0 / 5 - 0 ratings