React nativve 混合开发移动端应用环境搭建
安装软件清单:
Android Studio 版本:
Android Studio Giraffe | 2022.3.1 Patch 3
下载地址:https://developer.android.google.cn/studio/archive
JDK 版本 : JDK 17
下载地址: https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html
node 版本:18.17.1
下载地址:https://nodejs.org/download/release/
react native 移动端开发环境搭建:
https://reactnative.cn/docs/environment-setup
gradle 版本:8.0
下载地址:https://mirrors.cloud.tencent.com/gradle/gradle-0.8-all.zip
下载并安装配置环境变量,不在赘述.
注意: android studio 、jdk、node、版本之间必须兼容
环境搭建过程中遇到的问题:
1. android studio 加载并安装gradle超时问题.
找到C:/用户名/.gradle 文件中添加init.gradle ,内容如下:
buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/spring' } maven { url 'https://maven.aliyun.com/repository/spring-plugin' } maven { url 'https://maven.aliyun.com/repository/grails-core' } maven { url 'https://maven.aliyun.com/repository/apache-snapshots' } } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/spring' } maven { url 'https://maven.aliyun.com/repository/spring-plugin' } maven { url 'https://maven.aliyun.com/repository/grails-core' } maven { url 'https://maven.aliyun.com/repository/apache-snapshots' } } }
2. 执行命令:npx react-native doctor 检查环境搭建是否正常.
$ npx react-native doctor - Running diagnostics... Common ✓ Node.js - Required to execute JavaScript code ✓ npm - Required to install NPM dependencies ● Metro - Metro Bundler is not running Android ✖ Adb - No devices and/or emulators connected. Please create emulator with Android Studio or connect Android device. ✓ JDK - Required to compile Java code ✖ Android Studio - Required for building and installing your app on Android ✓ ANDROID_HOME - Environment variable that points to your Android SDK installation ✓ Gradlew - Build tool required for Android builds ✓ Android SDK - Required for building and installing your app on Android - Versions found: N/A - Version supported: 34.0.0
注:其他错误可以忽略,adb 没有配置
执行命令:npx react-native run-android 使用android 模拟器进行编译并安装
环境搭建完毕.