Thursday, January 26, 2023

React Native - Commands to develop the application

React Native is a popular JavaScript framework for building mobile application. It allows developers to create cross-platform apps for iOS and Android using a single codebase. One of the key tools for working with React Native projects is the command line interface (CLI), which provides a set of commands for creating, running, and debugging projects.

The primary command for working with React Native projects is "react-native". This command can be used to perform a variety of tasks, including creating a new project, running the project on an emulator or device, and debugging the project.



In this post, I'm going to share some useful commands to boost your developing skills. These commands are commonly used by the React Native developers:


react-native init: This command is used to create a new React Native project. It sets up the basic structure of a React Native project, including the necessary files and directories. You can use the command "react-native init [projectName]". 

react-native init developerlibs

react-native run-android: This command is used to run the project on an Android emulator or device. It builds the project and deploys it to the emulator or device for testing and debugging.

npx react-native run-android

react-native run-ios: This command is used to run the project on an iOS simulator or device. It builds the project and deploys it to the simulator or device for testing and debugging.

npx react-native run-ios

react-native start: This command is used to start the development server for the project. The development server is necessary for running and debugging the project in development mode.

npx react-native start 
// metro clean
npx react-native start -- --reset-cache

react-native log-android: This command is used to show the logs from the Android emulator or device. It allows developers to see console output, errors, and other information while the app is running.

npx react-native log-android

react-native log-ios: This command is used to show the logs from the iOS simulator or device. It allows developers to see console output, errors, and other information while the app is running.

npx react-native log-ios

react-native bundle: This command is used to bundle the code and assets of the project into a format that can be loaded by the app. This is typically used when building a release version of the app.

npx react-native bundle 

//Create Android APK
./gradlew assembleRelease

react-native upgrade: This command is used to upgrade an existing project to a new version of React Native. It updates the project's dependencies and makes any necessary changes to the project's code.

npx react-native upgrade

react-native link: This command is used to link native modules to the React Native app, this is useful for linking third-party libraries that have native dependencies.

npx react-native link

react-native info: This command is used to display information about the current environment and dependencies of a React Native project.

npx react-native info

npm cache clean --forceThis command is used to clean the React Native app:

npm cache clean --force
or
npx cache clean --force

 npm uninstall --saveThis command is used to uninstall libs from the React Native app: 

npm uninstall --save react-native-reanimated@2.2.2
or
npx uninstall --save react-native-reanimated@2.2.2

npm install --saveThis command is used to install libs in the React Native app: 

npm install --save react-native-reanimated@2.2.4
or
npx install --save react-native-reanimated@2.2.4

npm start --reset-cacheThis command is used to start the server and reset the cache of the React Native app: 

npm start --reset-cache
or
npx start --reset-cache

react-native run-android --deviceId=emulator-5556To run a React Native app on multiple devices at once using the react-native run-android command, you can specify the --deviceId flag followed by a comma-separated list of device IDs.This will run the app on the devices with the IDs "emulator-5554" and "emulator-5556" simultaneously.

You can also use the --deviceId flag without specifying any device IDs to run the app on all connected devices. For example:

npx react-native run-android --deviceId=emulator-5556
or
react-native run-android --deviceId=emulator-5554,emulator-5556

// Get list of connect device
npx react-native -list-avds


refresh project

1. delete "node_moduls"

2. delete package_lock.json

3. delete yarn.lock

4. npm install or npx yarn


Mac Specific Commands

pod installThis command used in iOS development to install and configure dependencies for a project that uses CocoaPods. CocoaPods is a dependency manager for iOS and macOS projects that helps developers manage and integrate third-party libraries and frameworks into their projects.

When you run the pod install command, it will look at the Podfile in your project's root directory and download and install the specified dependencies. It also creates an Xcode workspace file that includes your project and the installed pods, which you will use to build and run your app.

When you have added or changed any dependencies in your Podfile, you need to run pod install command again. This command will install the new pods and configure the Xcode project accordingly.

You can also use pod update command to update the pods to the latest version. this command will update the pods specified in the Podfile, or all pods if none are specified.

It's important to note that the pod install command should be run from the root directory of your project, where the Podfile is located.

pod install --verbose

//First you have to go ios diectory
// cd ios in terminal


M1 Mac specific Commands

The command arch -x86_64 pod install is used to install CocoaPods dependencies for an iOS project on a x86_64 architecture.

The arch -x86_64 flag is used to specify that the installation should be done for x86_64 architecture. This flag is used when you want to build your app for 64-bit devices, such as iPhone 5s and later, iPad Air and later, and iPad mini 2 and later.

When you run the command arch -x86_64 pod install it will install the dependencies specified in the Podfile for your project and will make sure that those dependencies are compatible with the x86_64 architecture.

arch -x86_64 pod install
                             and
arch -x86_64 pod install --repo-update


These are just some examples of the most common React Native commands. There are many other commands available that can be used for specific tasks and customization. By mastering these commands, you'll be able to quickly and efficiently work with React Native projects. 


Share:

Get it on Google Play

React Native - Start Development with Typescript

React Native is a popular framework for building mobile apps for both Android and iOS. It allows developers to write JavaScript code that ca...