Android platform commands for React Native CLI providing run-android, build-android, and log-android commands for managing Android development workflow
—
Network setup utilities for React Native development, including Metro bundler port forwarding and reverse proxy configuration for device connectivity.
Sets up reverse port forwarding to allow Android devices to connect to the Metro development server running on the development machine.
/**
* Set up reverse port forwarding for Metro bundler
* Runs 'adb reverse tcp:8081 tcp:8081' to allow loading the JS bundle from the packager
* @param packagerPort - Port number where Metro bundler is running
* @param device - Optional specific device identifier for reverse forwarding
*/
function tryRunAdbReverse(packagerPort: number | string, device?: string | void): void;Usage Examples:
import { tryRunAdbReverse } from "@react-native-community/cli-platform-android";
// Set up reverse forwarding for default Metro port
tryRunAdbReverse(8081);
// Set up reverse forwarding for custom port
tryRunAdbReverse(8082);
// Set up reverse forwarding for specific device
tryRunAdbReverse(8081, "emulator-5554");
// Use string port number
tryRunAdbReverse("8081");The tryRunAdbReverse function establishes a reverse TCP connection that allows Android devices and emulators to access the Metro development server running on the host machine. This is essential for React Native development as it enables:
By default, React Native's Metro bundler runs on port 8081. The reverse port forwarding maps:
This allows React Native apps running on Android devices to access http://localhost:8081 and reach the Metro server on the development machine.
The function includes built-in error handling for common scenarios:
Important Notes:
run-android commandInstall with Tessl CLI
npx tessl i tessl/npm-react-native-community--cli-platform-android