1, 参考文档
官方英文:https://facebook.github.io/react-native/docs/getting-started.html
官方中文:http://reactnative.cn/docs/0.27/getting-started.html#content
经验参考:http://blog.youkuaiyun.com/zivensonice/article/details/51333039
2, 安装步骤
-
安装jdk、Android Studio
官方建议jdk版本1.8+,实测1.7也可行
Android Studio已更新到2.0+版本,建议下载自带sdk的安装包
-
配置jdk、sdk环境变量
上边是android需要的环境
下边是react native安装方法
-
安装Chocolatey
Chocolatey是一个Windows上的包管理器,类似于linux上的yum和 apt-get。 你可以在其官方网站上查看具体的使用说明。一般的安装方法是在命令行中输入:
<code class="language-java hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@powershell</span> -NoProfile -ExecutionPolicy Bypass -Command <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"</span> && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
一般来说,使用Chocolatey来安装软件的时候,需要以管理员的身份来运行命令提示符窗口
-
安装Python 2
choco install python2
-
安装Node
choco install nodejs.install
-
React Native命令行工具(react-native-cli)
npm install -g react-native-cli
3,开始项目
react-native init AwesomeProject
cd
AwesomeProject
react
-
native run
-
android
-
注意
- 有些Android手机,运行React Native成功后,只得到一个白屏,什么都没有,这是因为手机的悬浮窗口权限被禁止了,要先去设置页面打开
- 小米手机需要关闭miui优化
~仅供参考~