Another solution that works for me is:
Make sure that in the .env file is defined in the root of the project. Then:
Edit your android\app\build.gradle with this:
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
// Import dotenv and load the environment vars
project.ext.env = new Properties()
file('../../.env').withInputStream { project.ext.env.load(it) }
react {
// React Native settings
}
android {
// other code
defaultConfig {
// Use the loaded environment variable
manifestPlaceholders = [MY_ENV_VAR: project.ext.env['MY_ENV_VAR']]
}
}
And in your android\app\src\main\AndroidManifest.xml add this:
<meta-data android:name="myEnvVar" android:value="${MY_ENV_VAR}" />