react-native-build-config is a utility module for React Native that exposes native build configuration variables (from Gradle for Android and Info.plist for iOS) directly to your JavaScript codebase. This allows developers to manage environment-specific settings, API endpoints, application version details (like `VERSION_NAME` and `VERSION_CODE`), and debug flags consistently across both native and JavaScript layers of their application. The current stable version is 0.3.2, with releases typically tied to compatibility updates for new React Native versions or addressing platform-specific nuances. Its primary differentiation is its direct integration with existing native build systems, avoiding the need for separate JavaScript-specific environment variable solutions and ensuring synchronization with native build variants.
npm install react-native-build-configVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to access various build configuration variables, including custom ones like `API_URL` and `SHOW_ERRORS`, as well as standard native build variables like `VERSION_NAME` and `DEBUG`, from the `BuildConfig` object within a React Native functional component.
For React Native < 0.60, use `react-native-build-config@0.1.0` and follow the manual linking instructions provided in the package's README, which involves modifying `android/settings.gradle`, `android/app/build.gradle`, and `MainActivity.java` (for Android).
Ensure variables are correctly declared in `android/app/build.gradle` (using `buildConfigField`) for Android builds and in `ios/YourApp/Info.plist` (using `<key>` and `<string>`/`<true>`/`<false>`) for iOS builds. Variable names must match exactly between native declarations and JS access.
Always anticipate the native type for known variables (e.g., `VERSION_CODE` as a number, `DEBUG` as a boolean) and perform type checks or explicit conversions in JavaScript if strict type handling is required.
Ensure that `react-native-build-config` is properly linked. If React Native < 0.60, manual linking is required. If RN >= 0.60, confirm auto-linking is working (e.g., by running `npx react-native run-android` or `npx react-native run-ios` to rebuild native modules). Also verify that the native build config (Gradle/Info.plist) has been properly configured and rebuilt.
Place `buildConfigField` declarations within the `defaultConfig { ... }` block or within specific `buildTypes { debug { ... } }` / `productFlavors { ... }` blocks in your `android/app/build.gradle` file. Double-check the syntax, ensuring correct type, name, and string-wrapped value format.No dependency data recorded yet.