1.登录 React Native 中文网
http://reactnative.cn/docs/0.45/getting-started.html

2.登录 Chocolatey 下载包管理工具
https://chocolatey.org/

3.打开 cmd 复制粘贴 Cmd.exe 中的命令代码
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

4.安装nodejs
choco install nodejs.install

5.安装python2
choco install python2

6.安装脚手架
npm install -g react-native-cli

7.创建项目
react-native init newPro

8.dirr 查看项目目录

9.安装jdk

10.安装android studio

11.启动模拟器

12.运行react native

第一步:react-native start

第二步:react-native run-android (重新开启一个终端)

13.手机或模拟器出现红底报错页面

14.摇一摇,出现操作列表

15.点击Dev Settings后,点击Debug server host & port for device,设置IP和端口

填入的的IP就是电脑的IP,不知道的话可以在命令行中输入ipconfig进行查询(但是不要在
上面的两个git bash里面查询),端口号固定8081。

16.再次摇一摇,选择Reload

17.找到项目文件下的 index.android.js 编写程序,摇一摇,选择Reload

常见问题:

1.项目创建过程中没有问题,但执行 $ react-native run-android 报错

$ react-native run-android
Scanning 554 folders for symlinks in C:\Users\Administrator\Desktop\react-
native\newPro\node_modules (73ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat
installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties
file or with an ANDROID_HOME environment variable.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

BUILD FAILED

Total time: 2 mins 31.924 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

原因解析:

无法找到SDK路径

解决方案:

在android文件夹下,新建 local.properties,添加路径

例:sdk.dir = /Users/hema/Library/Android/sdk

sdk.dir = D:/adt/sdk

2.没有接受SDK组件的许可协议

Warning: License for package Android Support Repository not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
[Android Support Repository].
Before building your project, you need to accept the license agreements and
complete the installation of the missing components using the Android Studio SDK
Manager.
Alternatively, to learn how to transfer the license agreements from one
workstation to another, go to http://d.android.com/r/studio-ui/export-
licenses.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

BUILD FAILED

Total time: 1 mins 44.091 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

原因解析:

没有接受SDK组件的许可协议

解决方案:

打开 SDK Manager.exe,在Extras下面找到 Android Support Repository 并 install

3.设备没有连接上

:app:assembleDebug
:app:installDebug
10:35:45 E/adb: Unable to obtain result of 'adb version'
:app:installDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: Could not create ADB Bridge. ADB location: D:\adt\sdk\platform-tools\adb.exe

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5 mins 57.339 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

原因解析:

设备没有连接上

解决方案:

(1) 执行 $ adb devices 发现 5037端口被占用

(2) 执行 $ netstat -aon|findstr "5037" 找到占用端口号的pid

(3) Ctrl + Shift + Esc 打开任务管理器 找到对应的PID,并结束该进程(我的是360手机助手,坑啊)

(4) 重新执行 react-native run-android

4.执行 react-native start 报错

Loading dependency graph, done.
ERROR EPERM: operation not permitted, lstat 'C:\Users\Administrator\Desktop\market\Market\android\app\build\intermediates\pre-dexed
\debug\debug_516e8c627655282fe10905a9a9ff86082b8f73d7.jar'
{"errno":-4048,"code":"EPERM","syscall":"lstat","path":"C:\\Users\\Administrator\\Desktop\\market\\Market\\android\\app\\build\
\intermediates\\pre-dexed\\debug\\debug_516e8c627655282fe10905a9a9ff86082b8f73d7.jar"}
Error: EPERM: operation not permitted, lstat 'C:\Users\Administrator\Desktop\market\Market\android\app\build\intermediates\pre-dexed\debug
\debug_516e8c627655282fe10905a9a9ff86082b8f73d7.jar'

问题解析:

不允许操作

解决方案:

保持 react-native run-android 的命令终端不动,重新执行 react-native start 即可。

5.Navigator 报错

Navigator is deprecated and has been removed from this package. It can now be installed and import from ‘react-native-deprecated-custom-components’ instead of ‘react-native’.

原因解析:

根据信息,react-native这个包中的Navigator已经被移除,而需要导入react-native-deprecated-custom-components这个包来使用Navigator。

解决方案:

1. 通过npm安装相应的库
  在项目根目录下输入npm install react-native-deprecated-custom-components --save 回车。

2. 在使用的JS文件中将Navigator引入进来,就是import
  import {Navigator} from ‘react-native-deprecated-custom-components’;

然后就可以在项目中正确使用Navigator了。

在windows下搭建React Native Android开发环境相关推荐

  1. Android之Windows下搭建React Native Android开发环境(差不多搞了一天)

    Android之Windows下搭建React Native Android开发环境               穷逼买不起mac,但是他们都说React Native Android只能在mac下面 ...

  2. 在Windows下搭建React Native Android开发环境常见问题

    1. task ':app:compileDebugJavaWithJavac'. > Could not find tools.jar 是没有配置Java环境 D:/Java\jdk1.8.0 ...

  3. windows下搭建Apache+Mysql+PHP开发环境

    原文:windows下搭建Apache+Mysql+PHP开发环境 要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位); Apache2.2; MySQL Server 5 ...

  4. python安卓版开发环境搭建_React Native Android 开发环境搭建(Windows 版)

    补上之前说的 Windows 系统的 React Native 开发环境搭建,坑还是比 Mac 环境下的多些.此文的受众还是已经搭建过 Android 开发环境的同学. 需要安装的软件 Chocola ...

  5. Windows下搭建Eclipse+Android4.0开发环境

    官方搭建步骤: http://developer.android.com/index.html 搭建好开发环境之前须要下载以下几个文件包: 一.安装Java执行环境JRE(没这个Eclipse执行不起 ...

  6. Windows下搭建NodeJS绿色版开发环境

    文章最初发布于 szhshp的第三边境研究所 , 转载请注明 开发背景 博客一直用的是Jekyll, 突然想玩玩NodeJS和Hexo, 于是就试着搭建一下 绿色环境, 基于Window8, 不需要管 ...

  7. React Native 一:开发环境搭建

    在学习React Native的过程中,相信对于一个App开发工程师,没有充分的学习过前端开发技术的同学来说,顺利的搭建好开发环境还是比较纠结的. 下面,我就根据我自己学习过程中的总结,跟大家讲解讲解 ...

  8. windows 下配置 react native 开发环境

    windows 下配置 react native 开发环境 安装nvm 由于react native 需要使用 NodeJs 4.0以上版本,为了方便切换NodeJs,首先我们需要安装nvm. 你可以 ...

  9. win7下搭建nginx+php的开发环境

    win7下搭建nginx+php的开发环境,需要的朋友可以参考下 一.下载相关软件 nginx下载:http://nginx.org/en/download.html nginx常见异常:http:/ ...

最新文章

  1. 凯文·凯利:下一个5000天的12个必然趋势!
  2. 计算机硬件选型报价,组装电脑硬件该怎么选择?这几个硬件要舍得花钱,千万别买错了!...
  3. Java后端:10w行级别数据的Excel导入优化记录
  4. python读写文件错误_Python读取csv文件错误解决方法
  5. C++中头文件和实现文件分离进行编译
  6. 企业IT架构转型之道 读书笔记-1.阿里巴巴集团中台战略引发的思考
  7. PHP云和骑士人才优缺点,PHP云人才系统与骑士cms人才系统对比点评
  8. 禁止微信中长按出现 复制文本和在浏览器中打开
  9. Win10(11)下Qt6.2编译Qtxlsx库
  10. 干货分享:app运营推广超实用计划书
  11. 支持国产ARM64架构部署,支持使用rz、sz命令上传下载文件,JumpServer堡垒机v2.12.0发布
  12. linux服务器扩容lun,FAQ-为什么2288H V5服务器扩容LUN后系统会报错
  13. 肺部结节智能诊断 csdn_在计算机的帮助下诊断肺部疾病
  14. mysql l查看历史等锁信息_查看锁信息(开启InnoDB监控)
  15. wsl2中安装中文输入法
  16. HTML5期末大作业:在线动漫网站设计——火影忍者(1页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码
  17. 【锐捷无线】用户隔离配置
  18. 计算机专业培养要求,计算机科学与技术专业人才培养目标及毕业要求(2015修订版)...
  19. 全自动磁环勾线机生产磁环电感能否代替人工?
  20. 【软件开发】使用Electron开发简单的记事本

热门文章

  1. 中美德工业互联网路径比较
  2. 《自然》 脑机接口新突破 人脑信号转文本准确率达97%
  3. 传感器融合:自动驾驶领域的另一个突围方向
  4. 腾讯投资过 600 多家公司不惊奇,京东也有出手 260+ | 大公司投资并购盘点
  5. 人类如何从不同角度识别物体?你需要对「小样本学习」有所了解
  6. 教你怎么卷过别人 | 每日趣闻
  7. 为什么 Python 会成为程序员害怕的编程语言?
  8. 云HBase发布全文索引服务,轻松应对复杂查询
  9. Spring Boot特性
  10. 基于OpenLayers+rbush实现高德轨迹样式