The preparatory work
- Node.js® is a JavaScript runtime based on the Chrome V8 engine. Download version v12 or later
- Install Homebrew first, refer to “Homebrew Installation and Use”.
- To install Watchman using Hombrew, see Installing Watchman.
- Yarn is a tool provided by Facebook to replace NPM. It speeds up the download and installation of Node modules
npm install -g yarn
- To install the JDK, see “Installing Java Development Kit on macOS”
- If you’ve never worked on an Android development environment before, be prepared for the tedious process. Please read the following instructions carefully and strictly follow the documentation for configuration operations. For details, see the macOS Download and Install Android Studio.
Install the react – native – cli
- In the project directory you specify, enter the command
react-native init AwesomeProject
- Continue to download
- Wait, wait, wait, wait, continue to download
- Continue to download
- Continue to download
- Continue to download
- Continue to download
- Continue to download
- Continue to download
- Continue to download
- Continue to download
- Continue to download
- The download is complete
Introduction to RN project directories
- On access, open the AwesomeProject directory
- Open AwesomeProject with VSCode, index.js is the entry file
Preparing Android Devices
You’ll need an Android device to run the React Native Android app. The device referred to here can be either a real machine or a simulator. All of our subsequent documentation does not distinguish between real machines and emulators unless otherwise specified. Android officially provides an emulator called Android Virtual Device (AVD).
The Android emulator is used here
You can use Android Studio to open the “Android” directory under your project, and then use the “AVD Manager” to view available virtual devices.
- Open an existing project
- Select the Android directory under the RN project
- Wait a moment
- Wait a moment
- If the website error, the probability is unstable science online, please solve
- Wait a moment
- A minute
- Six minutes
- Download details in the lower right corner
- If you have just installed Android Studio, you may need to create a virtual appliance first and use the “AVD Manager” to view the available virtual appliances. You can go to AVD Manager in either of the following places
- Click “Create Virtual Device…”
- Then select the type of device you want and click “Next”
- Then select Q API Level 29 Image and click Download
- Click Finish when the download is complete
- Click Next
- Click Finish
- This shows the emulator we just installed, now you should be able to click the green triangle button next to the virtual device to launch it, and once it’s up we can try running the application
- If you report an error, don’t panic
Compile and run the React Native application
- Make sure you run the emulator or connect to the real machine first, and then run it in your project directory
yarn android
oryarn react-native run-android
- If there are no problems with the configuration, you should see the application automatically installed and running on the device. Note that the first run requires downloading a large number of compile dependencies, which can take tens of minutes. This process relies heavily on a stable wall climbing tool, otherwise it will frequently experience connection timeouts and disconnections, resulting in no operation
- Go back to VSCode and try to modify the code in the app.js page