How To Create React Native Project
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
- Feedback
- Edit
Get started developing for Android using React Native
- 3 minutes to read
Thank you.
This guide will help you to get started using React Native on Windows to create a cross-platform app that will work on Android devices.
Overview
React Native is an open-source mobile application framework created by Facebook. It is used to develop applications for Android, iOS, Web and UWP (Windows) providing native UI controls and full access to the native platform. Working with React Native requires an understanding of JavaScript fundamentals.
-
Install Visual Studio Code (or your code editor of choice).
-
Install Android Studio for Windows. Android Studio installs the latest Android SDK by default. React Native requires Android 6.0 (Marshmallow) SDK or higher. We recommend using the latest SDK.
-
Create environment variable paths for the Java SDK and Android SDK:
- In the Windows search menu, enter: "Edit the system environment variables", this will open the System Properties window.
- Choose Environment Variables... and then choose New... under User variables.
- Enter the Variable name and value (path). The default paths for the Java and Android SDKs are as follows. If you've chosen a specific location to install the Java and Android SDKs, be sure to update the variable paths accordingly.
- JAVA_HOME: C:\Program Files\Android\Android Studio\jre\jre
- ANDROID_HOME: C:\Users\username\AppData\Local\Android\Sdk
-
Install NodeJS for Windows You may want to consider using Node Version Manager (nvm) for Windows if you will be working with multiple projects and version of NodeJS. We recommend installing the latest LTS version for new projects.
Create a new project with React Native
-
Use npx, the package runner tool that is installed with npm to create a new React Native project. from the Windows Command Prompt, PowerShell, Windows Terminal, or the integrated terminal in VS Code (View > Integrated Terminal).
npx react-native init MyReactNativeApp
-
Open your new "MyReactNativeApp" directory:
cd MyReactNativeApp
-
If you want to run your project on a hardware Android device, connect the device to your computer with a USB cable.
-
If you want to run your project on an Android emulator, you shouldn't need to take any action as Android Studio installs with a default emulator installed. If you want to run your app on the emulator for a particular device. Click on the AVD Manager button in the toolbar.
.
-
To run your project, enter the following command. This will open a new console window displaying Node Metro Bundler.
npx react-native run-android
Note
If you are using a new install of Android Studio and haven't yet done any other Android development, you may get errors at the command line when you run the app about accepting licenses for the Android SDK. Such as "Warning: License for package Android SDK Platform 29 not accepted." To resolve this, you can click the SDK Manager button in Android Studio . Or, you can list and accept the licenses with the following command, making sure to use the path to the SDK location on your machine.
C:\Users\[User Name]\AppData\Local\Android\Sdk\tools\bin\sdkmanager --licenses
-
To modify the app, open the
MyReactNativeApp
project directory in the IDE of your choice. We recommend VS Code or Android Studio. -
The project template created by
react-native init
uses a main page namedApp.js
. This page is pre-populated with a lot of useful links to information about React Native development. Add some text to the first Text element, like the "HELLO WORLD!" string shown below.<Text style={styles.sectionDescription}> Edit <Text style={styles.highlight}>App.js</Text> to change this screen and then come back to see your edits. HELLO WORLD! </Text>
-
Reload the app to show the changes you made. There are several ways to do this.
- In the Metro Bundler console window, type "r".
- In the Android device emulator, double tap "r" on your keyboard.
- On a hardware android device, shake the device to bring up the React Native debug menu and select `Reload'.
Additional resources
-
Develop Dual-screen apps for Android and get the Surface Duo device SDK
-
Add Windows Defender exclusions to improve performance
-
Enable Virtualization support to improve Emulator performance
Feedback
How To Create React Native Project
Source: https://docs.microsoft.com/en-us/windows/dev-environment/javascript/react-native-for-android
Posted by: williamsherat1979.blogspot.com
0 Response to "How To Create React Native Project"
Post a Comment