Premises
To allow for multi environment builds, the following Android flavors were set:
productFlavors {
development {
resValue "string", "app_name", "AppName Dev"
applicationId "com.org.nativeapp.development"
}
staging {
resValue "string", "app_name", "AppName Stag"
applicationId "com.org.nativeapp.staging"
}
production {
resValue "string", "app_name", "AppName"
}
}
On package.json, we could then build the app over different environments through the following scripts:
"android": "react-native run-android --mode=developmentDebug --appIdSuffix=development",
"android:prod": "react-native run-android --mode=productionDebug",
"android:stag": "react-native run-android --mode=stagingDebug --appIdSuffix=staging",
Introduction to the Problem
After upgrading a React Native project from 0.67.5 to latest (currently 0.71.3), when running metro through npx react-native start, we now have the possibility to build Android and iOS by simply pressing a key, as shown below:
Problem
Now, being able to directly build from the Metro process is very handy. But because those commands are (presumably) only running react-native run-android and react-native run-ios, those builds fail as, because of the multi environments setup, it'd need to run react-native run-android --mode=developmentDebug --appIdSuffix=development instead.
Conclusion
- Is there a way to modify the scripts that are run when building through the Metro session? If not,
- Is there a way to simply attach flags to those default commands, so to be able to build a specific Android flavor while on Metro?
Extra: Out of curiosity, on top of the default commands on the Metro session (r - reload the app, d - open developer menu, i - run on iOS, a - run on Android), would it be possible to add some other custom script?
Any comment on this is deeply appreciated - Thanks a ton in advance!
from React Native + Metro: Build Android / iOS with custom scripts

No comments:
Post a Comment