This Article Part of React Native Tutorial Series want to start from scrach follow below link
Today, we setup react native environment in macos for run react native app.
- Node.js and npm
- Java JRE and JDK
- React Native CLI
- Android Studio
Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system and Linux. The name is intended to suggest the idea of building software on the Mac depending on the user’s taste.
Install Homebrew using bellow command in Terminal.
1ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Install Node.js and npm
React need only webpack to bundle, compile, transpile the code. Then why do we need Node.js? 🤔 React Native comes with multiple built-in components and APIs to interact with both native IOS and Android platform. In some cases, we need to use native functionality that doesn’t provide by React Native. Most of the Native modules are distributed as npm packages. Therefore, we need to require npm and to initialize the npm we need to have Node.js as recommended. ⚠️ Remember, Node.js is not compulsory since you can download the packages and add to your library.
Install Node.js using bellow command in Terminal.
1brew install node
React Native uses watchman to detect real time code changes and it automatically build and push the update to your device without manually refreshing.
1brew install watchman
Install Java JRE and JDK
If you don’t have a complete installation of Java, the build scripts for react-native tend to complain and fail . Downloading Android Studio is not enough solution since it comes bundled with its own JRE.
1brew tap AdoptOpenJDK/openjdk
1brew cask install adoptopenjdk8
Install React Native
1npm install -g react-native-cli
Set up Xcode
Download Xcode via Mac App Store
- Open Xcode, Xcode > Preferences
- Goto the Locations tab
- Selecting the most recent version from the Command Line Tools dropdown
- Install cocoapods to MAC OS
1sudo gem install cocoapods
1sudo gem update — system
1sudo gem install -n /usr/local/bin cocoapods
CocoaPods manages library dependencies for your Xcode projects.
Set up Android Studio
Download Android Studio from below link https://developer.android.com/studio/index.html
- Open Android Studio
- Goto the Configure > SDK Manager
- Go to Appearance & Behavior → System Settings → Android SDK and check ✅ the box of latest version from Hide Obsolete Packages.
- Also check ✅ the boxes of below in Show package details,
- Android SDK Platform 28
- Intel x86 Atom_64 System Image or Google APIs Intel x86 Atom System Image
- Click “Apply” to download and install the Android SDK and related build tools.
- Set up environment variables to getting start with native code, Open terminal
1open -e .bash_profile
and paste below lines there.
1export ANDROID_HOME=$HOME/Library/Android/sdk2export ANDROID_HOME=$HOME/Library/Android/sdk3export PATH=$PATH:$ANDROID_HOME/emulator4export PATH=$PATH:$ANDROID_HOME/tools5export PATH=$PATH:$ANDROID_HOME/tools/bin6export PATH=$PATH:$ANDROID_HOME/platform-tools
Then you can create new Android Virtual Device (AVD) to run the application.
- Open Android Studio
- Goto the Configure > AVD Manager
- Create Virtual Device > pick any Phone from the list and click “Next”,
Click “Next” then “Finish” to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it , then proceed to the next step.
Create First App
The very first step is to initialize the app from the place where we need to create app
1react-native init first-app
If you want to start a new project with a specific React Native version,
1react-native init first-app --version X.XX.X
If you want use typescript with React Native,
1react-native init first-app --template typescript
Running your React Native Application in IOS
Running your React Native Application in AVD
The first time when you run this code you might get a build failed errors as,
🛑 Asking to add local.properties file
Create local.properties file inside android folder and add below code there.
1sdk.dir = /Users/pabasara/Library/Android/sdk
🛑 Asking to add keystroke
Go to directory
paste below code in terminal
1keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
Press enter until it gets ,
Is CN=y, OU=n, O=yes, L=no, ST=x, C=Y correct?
and type Y as response to terminate the command.
Here we go…. 👌 If everything working properly you can see app is running on both IOS emulator and AVD without errors. 😃 😃 😃
More From React Native Tutorial
- Introduction To React Native
- React Native Environment Setup using expo
- React Native Environment Setup for windows
- React Native Environment setup on Mac OS
- React Native Environment setup on linux
- React Native Project Structure
- React Native State
- React Native Props
- React Native Styling
- React Native Flexbox
- React Native Text
- React Native Textinput
- React Native Commands
- React Native ScrollView
- React Native Dark Mode
- React Native Fonts
- React Native SQLite
- React Native DatepickerAndroid
- React native ScrollView scroll to position
- How to align icon with text in react native
- React Native Image
- React Native Firebase Crashlytics
- React Native Async Storage
- React Native Share
Error & Issue Solution
- Task :app:transformDexArchiveWithDexMergerForDebug FAILED In React Native
- Expiring Daemon because JVM heap space is exhausted In React Native
- Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED In React Native
- Unable to determine the current character, it is not a string, number, array, or object in react native
- App crashed immediately after install react native video or track player
- how to delete SQLite database in android react native
- React native material dropdown twice click issue
- How to get the current route in react-navigation?
- how to disable drawer on the drawer navigation screen?
- Image not showing in ios 14 react native