React Native builds a development environment

Install dependencies

1. Download and install Node (version should be greater than or equal to 14)

2. Download and install Java SE Development Kit (JDK)

(React Native requires Java Development Kit [JDK] 11)

Enter on the command line javac -version to view the currently installed JDK version

https://adoptium.net/?variant=openjdk11&jvmVariant=hotspot

3. Download and install Android Studio

https://developer.android.google.cn/studio/

If the following image cannot be downloaded, you can temporarily turn off the proxy and download normally.

Insert image description here

3.1 Some instructions during the installation of Android Studio

(1) This place means that you do not have an SDK and allows you to set the proxy. If you do not set it here, click Cancel.

Insert image description here

(2) Android Studio will put your SDK download on the C drive by default, and then your C drive will explode. We choose Custom

Insert image description here

(3) Select the path of the custom SDK. This place allows you to set the path. After changing it, click Next (it will take a long time to download)

Insert image description here

It is best to hang a stable proxy to avoid network problems and download failure. Except for the installation path and sdk path, just keep the default ones.

3.2 Configure ANDROID_HOME environment variables and add some tool directories to the environment variable Path

%ANDROID_HOME%\platform-tools
%ANDROID_HOME%\emulator
%ANDROID_HOME%\tools
%ANDROID_HOME%\tools\bin

As shown below():
Insert image description here

Create new project

npx react-native init AwesomeProject

Use a real Android device

Turn on USB debugging and connect the device via USB data cable

Take Xiaomi as an example: continuously click [MIUI Version] to enter the developer options

Check whether your device can connect to ADB (Android Debug Bridge) correctly, use adb devicesthe command:
Insert image description here

Compile and run the React Native app

Make sure you run the emulator first or connect to a real device

Then in your project directory run yarn androideither yarn react-native run-android:

cd AwesomeProject
yarn android
# 或者
yarn react-native run-android

第一次运行时需要下载大量编译依赖,耗时可能几十分钟。一个好代理很重要

Successful running results:

Insert image description here

Android real machine debugging reports Failed to install the app

Maybe USB debugging is not turned on. In addition to turning on USB debugging, Xiaomi MIUI system also turns on USB installation.
Insert image description here

All in all, everything went smoothly!

Guess you like

Origin blog.csdn.net/qq_44721831/article/details/130156804