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
3. Download and install Android Studio
If the following image cannot be downloaded, you can temporarily turn off the proxy and download normally.
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.
(2) Android Studio will put your SDK download on the C drive by default, and then your C drive will explode. We choose Custom
(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)
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():
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 devices
the command:
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 android
either yarn react-native run-android
:
cd AwesomeProject
yarn android
# 或者
yarn react-native run-android
第一次运行时需要下载大量编译依赖,耗时可能几十分钟。一个好代理很重要
Successful running results:
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.
All in all, everything went smoothly!