### Start Metro Bundler
Source: https://github.com/lugg/react-native-config/blob/master/Example/0.73.4/README.md
Starts the Metro JavaScript bundler, which is essential for building and running React Native applications. This command can be executed using either npm or Yarn.
```bash
# using npm
npm start
# OR using Yarn
yarn start
```
--------------------------------
### Module Development Setup
Source: https://github.com/lugg/react-native-config/blob/master/windows/README.md
Steps to set up the development environment for contributing to the Windows implementation of react-native-config. This includes installing dependencies and matching package versions.
```shell
# Install Windows Development Dependencies (refer to official docs)
# Temporarily install react-native-windows package matching react-native version
# Example: if using react-native@0.62, install react-native-windows@^0.62
npm i react-native-windows@^0.62 --dev
# Open the corresponding RNCConfig.sln file (e.g., RNCConfig62.sln for react-native-windows@0.62)
```
--------------------------------
### Running Tests on Windows with WinAppDriver
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Outlines the steps to run automatic tests on Windows using the Example app, WinAppDriver, and Appium. This involves installing dependencies and executing specific console commands.
```console
yarn appium
yarn test:windows
```
--------------------------------
### Run React Native App on iOS
Source: https://github.com/lugg/react-native-config/blob/master/Example/0.73.4/README.md
Launches the React Native application on an iOS simulator or device. Ensure Metro bundler is running in a separate terminal. This command can be executed using either npm or Yarn.
```bash
# using npm
npm run ios
# OR using Yarn
yarn ios
```
--------------------------------
### Run React Native App on Android
Source: https://github.com/lugg/react-native-config/blob/master/Example/0.73.4/README.md
Launches the React Native application on an Android emulator or device. Ensure Metro bundler is running in a separate terminal. This command can be executed using either npm or Yarn.
```bash
# using npm
npm run android
# OR using Yarn
yarn android
```
--------------------------------
### Manual Link (Windows) - Visual Studio Solution Setup
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Instructions for integrating the RNCConfig project into a Visual Studio solution for Windows builds.
```csharp
// 1. Open the solution in Visual Studio 2019
// 2. Right-click Solution icon in Solution Explorer > Add > Existing Project
// - if using `react-native-windows@0.62` or later select `node_modules\react-native-config\windows\RNCConfig\RNCConfig.vcxproj`
// - if using `react-native-windows@0.61` select `node_modules\react-native-config\windows\RNCConfig61\RNCConfig61.vcxproj`
// **windows/myapp/myapp.vcxproj**
// Add a reference to `RNCConfig` to your main application project. From Visual Studio 2019:
// 1. Right-click main application project > Add > Reference...
// Check `RNCConfig` from Solution Projects.
// **pch.h**
// Add `#include "winrt/RNCConfig.h"`.
// **app.cpp**
// Add `PackageProviders().Append(winrt::RNCConfig::ReactPackageProvider());` before `InitializeComponent();`.
```
--------------------------------
### Android Gradle Setup (app/build.gradle)
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Snippet for `android/app/build.gradle` to add the react-native-config module as an implementation dependency.
```gradle
dependencies {
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-config')
}
```
--------------------------------
### Manual Install React Native Config (RNW >= 0.62)
Source: https://github.com/lugg/react-native-config/blob/master/windows/README.md
Steps to manually install react-native-config for React Native Windows 0.62. This involves npm installation and adding the project to your Visual Studio solution, followed by reference updates.
```shell
npm install react-native-config --save
# Open your solution in Visual Studio 2019 (e.g., windows\yourapp.sln)
# Right-click Solution icon in Solution Explorer > Add > Existing Project...
# Add node_modules\react-native-config\windows\RNCConfig\RNCConfig.vcxproj
# Right-click main application project > Add > Reference...
# Select RNCConfig in Solution Projects
# In app pch.h add: #include "winrt/RNCConfig.h"
# In App.cpp add: PackageProviders().Append(winrt::RNCConfig::ReactPackageProvider()); before InitializeComponent();
```
--------------------------------
### Run Windows App with Default .env
Source: https://github.com/lugg/react-native-config/blob/master/Example/README.md
Executes the React Native Windows application. It loads configuration variables from the default `.env` file.
```console
npx react-native run-windows
```
--------------------------------
### Android Gradle Setup (settings.gradle)
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Configuration snippet for `android/settings.gradle` to include the react-native-config module into your Android project.
```gradle
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
```
--------------------------------
### Manual Install React Native Config (RNW 0.61)
Source: https://github.com/lugg/react-native-config/blob/master/windows/README.md
Instructions for manually installing react-native-config for React Native Windows 0.61. This process is similar to RNW 0.62 but uses a different .vcxproj file path.
```shell
# Follow the same steps as for RNW 0.62, but use the following path in step 4:
# Add node_modules\RNCConfig\windows\RNCConfig61\RNCConfig.vcxproj
```
--------------------------------
### iOS Podfile Flipper Integration with Post-Install Hook
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Shows how to correctly integrate `react-native-config` environment file setup with Flipper when both use `post_install` hooks in the Podfile. The Flipper post-install logic must be moved into the new hook to avoid conflicts.
```diff
target 'MyApp' do
# ...
use_flipper!
- post_install do |installer|
- flipper_post_install(installer)
- end
end
post_install do |installer|
+ flipper_post_install(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'react-native-config'
config.build_settings['ENVFILE'] = ENVFILES[config.name]
end
end
end
end
```
--------------------------------
### Install react-native-config
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Command to add the react-native-config package to your project dependencies using Yarn.
```bash
$ yarn add react-native-config
```
--------------------------------
### Manual Link (iOS/macOS) - Xcode Project Setup
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Steps to manually link the library in Xcode by adding the project and linking the static library.
```objective-c
// 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
// 2. Go to `node_modules` ➜ `react-native-config` ➜ `ios` and add `ReactNativeConfig.xcodeproj`
// 3. Expand the `ReactNativeConfig.xcodeproj` ➜ `Products` folder
// 4. In the project navigator, select your project. Add `libRNCConfig.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
// 5. Go the Build Settings tab. Make sure All is toggled on (instead of Basic)
// 6. Look for Header Search Paths and add `$(SRCROOT)/../node_modules/react-native-config/ios/**` as `non-recursive`
```
--------------------------------
### Run Android App with Default .env
Source: https://github.com/lugg/react-native-config/blob/master/Example/README.md
Executes the React Native Android application. It automatically loads configuration variables from the `.env` file located in the project root.
```bash
react-native run-android
```
--------------------------------
### Install React Native Config Automatically (RNW >= 0.63)
Source: https://github.com/lugg/react-native-config/blob/master/windows/README.md
Installs the react-native-config module using npm for automatic linking with React Native Windows versions 0.63 and later. This is the recommended approach for newer versions.
```javascript
npm i react-native-config --save
```
--------------------------------
### iOS/macOS Scheme Setup for Environment Files
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Provides instructions for setting up separate Xcode schemes for different environment files. This involves duplicating an existing scheme, renaming it, and marking it as shared. A run script action is then added to copy the appropriate .env file.
```bash
cp "${PROJECT_DIR}/../.env.staging" "${PROJECT_DIR}/../.env" # replace .env.staging for your file
```
--------------------------------
### Install Dependencies with CocoaPods
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Command to install native dependencies for iOS projects using CocoaPods after adding the package.
```bash
(cd ios; pod install)
```
--------------------------------
### TypeScript Usage Example
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Demonstrates how to import and access environment variables using the react-native-config module in a TypeScript application.
```ts
import Config from 'react-native-config';
console.log(Config.HOSTNAME);
```
--------------------------------
### Android Manifest Meta-data
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Shows an example of how environment variables can be referenced in the AndroidManifest.xml file, often for API keys or configuration values.
```xml
```
--------------------------------
### iOS App Extension Pod Installation
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Shows how to add react-native-config as a dependency for iOS App Extensions, including the specific extension target configuration.
```ruby
target 'ShareExtension' do
platform :ios, '9.0'
pod 'react-native-config', :path => '../node_modules/react-native-config'
# For extensions without React dependencies
pod 'react-native-config/Extension', :path => '../node_modules/react-native-config'
end
```
--------------------------------
### Run Windows App with Custom .env File
Source: https://github.com/lugg/react-native-config/blob/master/Example/README.md
Executes the React Native Windows application, specifying a custom environment file. The `ENVFILE` variable is set to direct the build process to load configuration from a file other than the default `.env`.
```console
set ENVFILE=.env.production
npx react-native run-windows
```
--------------------------------
### Run Android App with Custom .env File
Source: https://github.com/lugg/react-native-config/blob/master/Example/README.md
Executes the React Native Android application, specifying a custom environment file. The `ENVFILE` variable directs the build process to load configuration from a file other than the default `.env`.
```bash
ENVFILE=.env.prod react-native run-android
```
--------------------------------
### Jest Mock for react-native-config
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Provides an example of how to mock the `react-native-config` module for use in Jest tests. This allows testing components that rely on environment variables without needing to run the native build process.
```javascript
// __mocks__/react-native-config.js
export default {
FOO_BAR: 'baz',
};
```
--------------------------------
### iOS/macOS Native Usage (Objective-C)
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Provides examples of how to access environment variables from your .env file within Objective-C classes on iOS and macOS platforms.
```objective-c
// import header
#import "RNCConfig.h"
// then read individual keys like:
NSString *apiUrl = [RNCConfig envFor:@"API_URL"];
// or just fetch the whole config
NSDictionary *config = [RNCConfig env];
```
--------------------------------
### Environment File Selection (Bash/Windows)
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Demonstrates how to specify a different .env file for loading environment variables using the ENVFILE environment variable across different shells.
```bash
$ ENVFILE=.env.staging react-native run-ios # bash
```
```powershell
$ SET ENVFILE=.env.staging && react-native run-ios # windows
```
```powershell
$ env:ENVFILE=".env.staging"; react-native run-ios # powershell
```
--------------------------------
### Android Release Build Configuration
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Demonstrates how to assemble Android releases with a specific environment configuration using a custom ENVFILE. This involves navigating to the android directory and executing a Gradle command with the ENVFILE variable set.
```bash
cd android && ENVFILE=.env.staging ./gradlew assembleRelease
```
```bash
cd android && export ENVFILE=.env.staging ./gradlew bundleRelease
```
--------------------------------
### iOS Podfile Configuration for Environment Files
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Illustrates how to configure environment files per build configuration (Debug, Release) by defining a map in the Podfile and assigning the correct ENVFILE path within the `post_install` hook. This method is useful when build configurations are already separated.
```ruby
ENVFILES = {
'Debug' => '$(PODS_ROOT)/../../.env.debug',
'Release' => '$(PODS_ROOT)/../../.env.production',
}
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'react-native-config'
config.build_settings['ENVFILE'] = ENVFILES[config.name]
end
end
end
end
```
--------------------------------
### Android MainApplication.java Integration
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Code to integrate the RNCConfigPackage into your `MainApplication.java` file to register the native module.
```java
import com.lugg.RNCConfig.RNCConfigPackage;
@Override
protected List getPackages() {
return Arrays.asList(
new MainReactPackage()
new RNCConfigPackage()
);
}
```
--------------------------------
### Android Auto-Integration with RN-Integrate
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Command to automatically apply extra steps for Android integration using the react-native-integrate CLI tool.
```bash
npx react-native-integrate react-native-config
```
--------------------------------
### Windows Native Usage (C++)
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Demonstrates how to access environment variables from your .env file within C++ code for Windows applications.
```cpp
std::string api_key = ReactNativeConfig::API_KEY;
```
--------------------------------
### Android Gradle Build Flavor Configuration
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Shows how to map different build flavors (like debug, release) to specific environment files within the `build.gradle` file. This configuration must precede the `apply from` call for the dotenv plugin.
```gradle
project.ext.envConfigFiles = [
debug: ".env.development",
release: ".env.production",
anothercustombuild: ".env",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
```
--------------------------------
### Android dotenv.gradle Plugin Application
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Manual application of the dotenv.gradle plugin in `android/app/build.gradle` to load environment variables.
```gradle
// 2nd line, add a new apply:
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
```
--------------------------------
### iOS Build Script for XCConfig
Source: https://github.com/lugg/react-native-config/blob/master/README.md
A run script action for Xcode build phases that generates a temporary XCConfig file to expose environment variables to the build settings and Info.plist.
```bash
"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb" "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"
```
--------------------------------
### Dexguard Configuration for Build Config Package
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Explains the necessary configuration for Dexguard users to preserve the build config package name during the shrinking phase, preventing potential issues with `react-native-config`.
```proguard
-keepresources string/build_config_package
```
--------------------------------
### Android Gradle Configuration
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Illustrates how to read environment variables from your .env file within your Android Gradle build scripts for application configuration.
```groovy
defaultConfig {
applicationId project.env.get("APP_ID")
}
```
--------------------------------
### TypeScript Declaration for .env
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Provides type safety and autocompletion for your .env files in TypeScript projects. Define an interface for your configuration variables to ensure correct usage.
```ts
declare module 'react-native-config' {
export interface NativeConfig {
HOSTNAME?: string;
}
export const Config: NativeConfig
export default Config
}
```
--------------------------------
### iOS XCConfig File Content
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Defines the content for an XCConfig file used to integrate environment variables into Xcode build settings and Info.plist.
```text
#include? "tmp.xcconfig"
```
--------------------------------
### Android BuildConfig Package Name Configuration
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Configuration in `android/app/build.gradle` to specify the package name for BuildConfig, useful when using `applicationIdSuffix` or custom `applicationId`.
```gradle
defaultConfig {
...
resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML"
}
```
--------------------------------
### Android Native Usage (Java)
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Shows how to access environment variables from your .env file within Java classes on Android, typically via the BuildConfig class.
```java
public HttpURLConnection getApiClient() {
URL url = new URL(BuildConfig.API_URL);
// ...
}
```
--------------------------------
### Access Config Variables in React Native
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Demonstrates how to import the Config module and access environment variables defined in a .env file within your JavaScript code. These variables are exposed directly as properties of the Config object.
```javascript
import Config from "react-native-config";
Config.API_URL; // 'https://myapi.com'
Config.GOOGLE_MAPS_API_KEY; // 'abcdefgh'
```
--------------------------------
### Android Gradle Type Casting
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Demonstrates how to cast environment variables, which are read as strings, to other types like integers within Android Gradle build scripts.
```groovy
versionCode project.env.get("VERSION_CODE").toInteger()
```
--------------------------------
### Android Proguard Configuration
Source: https://github.com/lugg/react-native-config/blob/master/README.md
Details how to prevent Proguard from renaming the `BuildConfig` Java class, which is necessary for `react-native-config` to function correctly during release builds. An exception rule must be added to `android/app/proguard-rules.pro`.
```proguard
-keep class com.mypackage.BuildConfig { *; }
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.