I am trying to get flavors or build variants running in android for my react-native project.
Via Schemes I got the same running on iOS, but Android does not want to follow. I guess something I am doing wrong.
Steps that I took so far (all in a fresh project to test):
project.ext.envConfigFiles = [ staging: ".env.staging", production: ".env.production", ] apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
flavorDimensions "appType" productFlavors { staging { dimension "appType" applicationIdSuffix ".staging" // resValue "string", "app_name", "Config Demo-Staging" } production { dimension "appType" applicationIdSuffix ".production" // resValue "string", "app_name", "Config Demo" } }
"scripts": { "androidStagingDebug": "react-native run-android --variant=stagingDebug", "androidProductionDebug": "react-native run-android --variant=productionDebug", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." },
Now I want to start the app from Android Studio and just check via:
import config from 'react-native-config';
and respectively in a later function:
console.log(config)
whether I read the right file when choosing a build variant.
Unfortunately it either does not load any or only debug. Any idea?! Additionally in some variants it seems the app does not connect to metro..
Your build.gradle file seems ok.
Mine is slightly different though :
project.ext.envConfigFiles = [
prod: "./environment/.prod",
beta: "./environment/.beta",
alpha: "./environment/.alpha",
]
Then :
flavorDimensions "default"
productFlavors {
prod {
applicationIdSuffix ".prod"
}
beta {
applicationIdSuffix ".beta"
}
alpha {
applicationIdSuffix ".alpha"
}
}
Like I said in a comment earlier, I don't use any script to launch the app, I just select the build variant in Android Studio.
Here's the resource I used:
And here's an example project:
https://github.com/therealemjy/react-native-tuto-multiple-environments/tree/result
Hope it helps a bit.