i wanna learn react native cli
I'll help you learn React Native CLI! React Native CLI is the command-line interface for creating and managing React Native projects. Let me break down the key concepts and commands you need to know.
React Native CLI is a tool that helps you:
First, you'll need to install React Native CLI globally:
npm install -g @react-native-community/cli
# Create a new React Native project
npx react-native@latest init MyAwesomeProject
# Navigate to your project
cd MyAwesomeProject
# Start the Metro bundler
npx react-native start
# Run on Android (in a separate terminal)
npx react-native run-android
# Run on iOS (macOS only)
npx react-native run-ios
# Run on specific iOS simulator
npx react-native run-ios --simulator="iPhone 15 Pro"
# Clean build cache
npx react-native clean
# Link native dependencies (for older RN versions)
npx react-native link
# Get device/simulator info
npx react-native info
# Log Android device logs
npx react-native log-android
# Log iOS device logs
npx react-native log-ios
sudo gem install cocoapods
When you create a new project, you'll see:
MyAwesomeProject/
├── android/ # Android-specific code
├── ios/ # iOS-specific code
├── src/ # Your React Native code
├── App.tsx # Main app component
├── index.js # Entry point
├── package.json # Dependencies
└── metro.config.js # Metro bundler config
npx react-native start
npx react-native run-android
or npx react-native run-ios
r
in Metro terminal or shake deviceReact Native CLI:
Expo CLI (now recommended for beginners2):
Once you're comfortable with the basics:
The React Native team now recommends starting with Expo for new projects2, but learning React Native CLI gives you deeper understanding of how React Native works under the hood.
Set up a new React Native CLI project and run it on a simulator
I'll guide you through setting up a new React Native CLI project and running it on a simulator step by step!
Before we start, make sure you have these installed:
# Check Node.js version (should be 18+)
node --version
# Check if you have React Native CLI
npx react-native --version
# Create a new React Native project
npx react-native@latest init MyFirstApp
# Navigate to the project directory
cd MyFirstApp
This will create a new React Native project with the latest version and set up all the necessary files.
Open a terminal in your project directory and start Metro (the JavaScript bundler):
# Start Metro bundler
npx react-native start
Keep this terminal window open - Metro needs to run continuously while developing.
# For macOS/Linux - add to ~/.bash_profile or ~/.zshrc
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/platform-tools
# For Windows - add to system environment variables
ANDROID_HOME = C:\Users\YourUsername\AppData\Local\Android\Sdk
Create an Android Virtual Device (AVD):
# In a NEW terminal window (keep Metro running in the first one)
npx react-native run-android
xcode-select --install
sudo gem install cocoapods
cd ios
pod install
cd ..
# Run on default iOS simulator
npx react-native run-ios
# Or specify a specific simulator
npx react-native run-ios --simulator="iPhone 15 Pro"
# List available simulators
xcrun simctl list devices
Once your app is running, you should see:
# Reload the app (in Metro terminal)
r
# Open developer menu (in simulator)
# iOS: Cmd + D
# Android: Cmd + M (Mac) or Ctrl + M (Windows/Linux)
# Clear Metro cache if you encounter issues
npx react-native start --reset-cache
# Clean build if you encounter native issues
npx react-native clean
# If build fails, try cleaning
cd android
./gradlew clean
cd ..
# If emulator doesn't start
emulator -list-avds
emulator -avd YourAVDName
# Clean iOS build
cd ios
xcodebuild clean
cd ..
# Reinstall pods
cd ios
pod deinstall
pod install
cd ..
# Reset Metro cache
npx react-native start --reset-cache
# Kill any existing Metro processes
npx react-native start --port=8082
Your new project will have this structure:
MyFirstApp/
├── android/ # Android native code
├── ios/ # iOS native code
├── App.tsx # Main React component
├── index.js # App entry point
├── package.json # Dependencies
├── metro.config.js # Metro bundler config
└── babel.config.js # Babel configuration
Once your app is running successfully:
Your React Native development environment is now ready! The app should automatically reload when you make changes to your code.
in roman languague