lugg / react-native-config

Bring some 12 factor love to your mobile apps!
MIT License
4.81k stars 659 forks source link

[Android] Possible to use env vars in strings.xml for style/item ? #37

Open atinder opened 7 years ago

atinder commented 7 years ago

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>
justinmoon commented 7 years ago

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

prtkkmrsngh commented 7 years ago

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

joncursi commented 7 years ago

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

joncursi commented 7 years ago

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

  <string name="facebook_app_id">appIDhere</string>
prtkkmrsngh commented 7 years ago

@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.

alfonsodev commented 6 years ago

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 ?

fforres commented 6 years ago

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?

alfonsodev commented 6 years ago

@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!

sundariragavan commented 6 years ago

Same problem here.Any update?

lucianomlima commented 4 years ago

Any news on that?

mchjohn commented 2 years ago

Try it

<resources>
    <string name="facebook_app_id">{$FACEBOOK_APP_ID}</string>
    <string name="fb_login_protocol_scheme">{$FACEBOOK_LOGIN_PROTOCOL_SCHEME}</string>
</resources>
Makhdoom-Sharif commented 1 year ago

I am trying to access the string from .env in strings.xml but it shows the error: resource string/APP_NAME (aka com.APP:string/APP_NAME) not found . Any update?

LuizCristino commented 1 year ago

Looks like any access to string xml results on not found only on CI. Also looking for a solution

tkyr-hh commented 1 year ago

this issue happened to me as well but only on CircleCI pipeline, not happening in local, I don't know why

KFrysztak commented 1 year ago

any update on it? I am also facing the same issue. Locally it works in a perfect way but not on CI.

tkyr-hh commented 1 year ago

@KFrysztak for me the issue is that I'm decrypting the env file in the first job of the NPM packages installation, not in the APK build job, and it turns out that the ENV file does not exist because I need it to persist in the workspace, but this is not wise, I've put the env decryption step in the APK build job, before the step of the assemble release step, and it worked as expected.

MhtChawlaRutrust commented 1 year ago

I am trying to access the string from .env in strings.xml but it shows the error: resource string/APP_NAME (aka com.APP:string/APP_NAME) not found . Any update?

any workaround?