Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access environment variable in React-Native AndroidManifest.xml

I'm new to React Native. The task at hand is to set my Google API key in AndroidManifest.xml without exposing it, when pushed to GitHub. I set up an environment variable called API_KEY, but however I want to access it in the .xml, I get an error when trying to spin up the dev server.

So far I tried:

android:value=${env.API_KEY}
android:value="${env.API_KEY}"
android:value="${API_KEY}"

Thank you!

like image 564
DBencz Avatar asked Jun 04 '26 12:06

DBencz


1 Answers

Based on the second comment (from kenmistry), the solution that worked for me was indeed to create a placeholder in build.gradle, but since, for whatever reason, configuring and referring a .env file did't work, I invoked my environment variables like so in build.gradle:

manifestPlaceholders = [API_KEY: "$System.env.API_KEY"]

and accessed it in the .xml as suggested by kenmistry:

android:value="${API_KEY}"
like image 196
DBencz Avatar answered Jun 07 '26 03:06

DBencz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!