tezvyn:

Build flavors and schemes for RN environments

AI-drafted, machine-checkedSource: interviewintermediate
WHAT IT TESTS

managing dev, staging, and prod builds natively.

OUTLINE

Android productFlavors with distinct applicationId and resources, iOS schemes plus configurations and targets, environment config injection.

WHAT THIS TESTS The interviewer wants to know if you can ship dev, staging, and production variants that install side by side with the correct identity, and whether you understand the native build systems rather than only the JS layer.

A GOOD ANSWER COVERS On Android you define productFlavors inside android/app/build.gradle, for example dev, staging, and prod, each setting its own applicationIdSuffix so the package id differs, a resValue or strings override for the app name, and a flavor-specific res directory (src/dev/res) for distinct launcher icons. Gradle then generates build types crossed with flavors, like devDebug. On iOS the equivalent is build configurations (Debug, Release, plus copies) paired with schemes, and often duplicate targets. You override PRODUCT_BUNDLE_IDENTIFIER, the display name in Info.plist, and point to different asset catalogs per configuration, frequently via xcconfig files. Environment values such as the API base URL are injected through gradle buildConfigField or xcconfig and exposed to JS through a library like react-native-config, so the JavaScript stays environment-agnostic.

COMMON WRONG ANSWERS Hardcoding API URLs in JavaScript or toggling on __DEV__ conflates debug builds with environments and breaks a staging release build. Reusing a single bundle identifier means installing staging overwrites production on the same device. Storing secrets in the JS bundle exposes them since the bundle is readable.

LIKELY FOLLOW-UPS How do you keep icons and names in sync across both platforms? Maintain per-flavor resource folders and per-configuration asset catalogs, automated in CI. How do you select a flavor at build time? Use gradle assembleDevRelease or xcodebuild -scheme. How do secrets stay safe? Inject at build time from CI secrets, never commit them.

ONE CONCRETE EXAMPLE For a banking app you create flavors dev, staging, prod with applicationIdSuffix .dev and .staging, so com.bank.dev and com.bank install together. react-native-config reads .env.staging to set API_URL. On iOS three schemes map to three configurations, each with its own bundle id and a yellow staging icon, letting QA run all three on one phone.

Read the original → praveen-me.in

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.