Windows平台搭建React Native开发环境

2019-07-24  本文已影响0人  Huangrong_000

1、安装Java

2、安装Android SDK

3、安装Node.js

4、安装React Native命令行工具

npm config set registry https://registry.npm.taobao.org --global

npm config set disturl https://npm.taobao.org/dist --global

npm install -g react-native-cli


在这里插入图片描述

安装完成后可以通过react-native --h查看帮助


在这里插入图片描述

5、初始化React-native项目

6、运行项目

手机界面错误提示:
The development server returned response error code: 500
URL: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false

在这里插入图片描述
npm服务器端

Loading dependency graph, done.
error: bundling failed: Error: Unable to resolve module @babel/runtime/helpers/ interopRequireDefault from D:\RNProject\AwesomeProject\index.js: Module @bab el/runtime/helpers/interopRequireDefault does not exist in the Haste module map

image

首先,按照错误提示修复
npm watchman watch-del-all
npm rm -rf node_modules && npm install
npm rm -rf /tmp/metro-bundler-cache-*
npm rm -rf /tmp/haste-map-react-native-packager-*
发现仍然有错,因为当前安装的react-native-cli的版本为2.0.1 对应react-native版本为0.55.4能正常运行


在这里插入图片描述

通过react-native -v查看当前使用的react-native是最新版本0.57.1


在这里插入图片描述
1、npm install --save react-native@0.55.4;
在这里插入图片描述

2、react-native upgrade,一路y,最后提示 Successfully upgraded this project to react-native v0.55.4;


在这里插入图片描述

:app:generateDebugBuildConfig FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
java.io.IOException: Could not delete path 'D:\RNProject\AwesomeProject\android\app\build\generated\source\buildConfig\debug\com'.
BUILD FAILED


在这里插入图片描述

根据提示是android目录下build错误,删掉了android/app/build目录的几个文件夹


在这里插入图片描述

再次运行

FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:installDebug'.
com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to finalize session : -26:
Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED


在这里插入图片描述

根据错误提示,是关于项目Android编译版本的问题,参考https://blog.csdn.net/qq_15364915/article/details/68059999一文的解决方法

  1. 先修改android 下gradle下wrapper的gradle-wrapper.properties配置文件,
    distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
  2. app下面的build.gradle 文件:buildToolsVersion "25.0.0"


    在这里插入图片描述
  3. android 工程下的build.gradle 文件: dependencies { classpath 'com.android.tools.build:gradle:2.3.0' }


    在这里插入图片描述

    然后重新跑工程,运行 react-native run-android ,运行成功了

上一篇 下一篇

猜你喜欢

热点阅读