React Native is a popular framework for building mobile applications using JavaScript and React. To work with React Native, you’ll often use the command-line interface (CLI) to perform various tasks. Here are some of the popular commands and their descriptions:
- Create a New React Native Project:
> npx react-native init MyApp
This command initializes a new React Native project called “MyApp” in the current directory. - Start the Development Server:
> npx react-native start
This command starts the Metro Bundler, which is the development server for your React Native app. - Run the App on an Android Emulator:
>npx react-native run-android
Use this command to build and run your React Native app on an Android emulator. - Run the App on an iOS Simulator:
> npx react-native run-ios
This command builds and runs your React Native app on an iOS simulator. You can specify a specific simulator with the--simulator
flag. - Install a New Dependency:
> npm install package-name
> yarn add package-name
You can use npm or yarn to install javascript packages or libraries into react-native projects. If you are using yarn, you can use the second command. - Link Native Modules:
> npx react-native link
If you are using a react-native library of version less than 0.64, then you need to run the above command just after adding new font family, packages. - Generate a Release Build (Android):
> cd android && ./gradlew bundleRelease
This command generates a release bundle for your Android app. But You’ll need to configure signing and other release settings in your Android project such as generating keystore files for release mode. - Generate a Release Build (iOS):
> npx react-native run-ios --configuration Release
This command generates a release build for your iOS app. You’ll need to configure signing and other release settings in your Xcode project. - Generate a Release Build (Android):
> npx react-native run-android --variant release
This command runs your project in your real device or emulator in release mode, but your app should have a keystore file linked with your project in release mode. - Create a Release APK (Android):
> cd android && ./gradlew assembleRelease
If you have created a keystore file in release mode then, This command creates a debug APK for your Android app, which you can send for testing. - Clear npm cache forcibly:
> npm cache clean --f
This command clears all npm-related cache from the project forcefully. sometimes this command helps a lot to solve cache issues. - Install dependencies in IOS:
> pod install
This command is very necessary command if you are running your React native project on Mac. This project is run just after you install JavaScript libraries.