加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React native 安装

发布时间:2020-12-15 05:14:43 所属栏目:百科 来源:网络整理
导读:1,参考文档 官方英文: https://facebook.github.io/react-native/docs/getting-started.html 官方中文: http://reactnative.cn/docs/0.27/getting-started.html#content 经验参考: http://blog.csdn.net/zivensonice/article/details/51333039 2,安装步骤

1,参考文档

官方英文:https://facebook.github.io/react-native/docs/getting-started.html
官方中文:http://reactnative.cn/docs/0.27/getting-started.html#content经验参考:http://blog.csdn.net/zivensonice/article/details/51333039

2,安装步骤

  1. 安装jdk、Android Studio
    官方建议jdk版本1.8+,实测1.7也可行
    Android Studio已更新到2.0+版本,建议下载自带sdk的安装包

  2. 配置jdk、sdk环境变量

    • jdk环境变量配置不缀叙

    • 确保ANDROID_HOME环境变量正确地指向了你安装的Android SDK的路径

    • 将ANDROID_HOME配入Path系统路径
      %ANDROID_HOME%tools;%ANDROID_HOME%platform-tools

上边是android需要的环境
下边是react native安装方法
  1. 安装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%chocolateybin</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来安装软件的时候,需要以管理员的身份来运行命令提示符窗口

  2. 安装Python 2

    choco install python2

  3. 安装Node

    choco install nodejs.install

  4. React Native命令行工具(react-native-cli)

    npm install -g react-native-cli

3,开始项目
react-native init AwesomeProject
cd AwesomeProject
react - native run android

  • 在浏览器中打开http://localhost:8081/index.android.bundle?platform=android,如果得到以下页面,表示服务已经开启

  • 不要关闭上一个命令行,新开一个命令行工具,输入

    react-native run-android

    • 如果是真机,第一次运行肯定会报错

    • 需要让手机和电脑处于同一个wifi网络下,然后设置端口信息 (摇一摇手机,或者按menu键)

      ip+8081端口

注意

  • 有些Android手机,运行React Native成功后,只得到一个白屏,什么都没有,这是因为手机的悬浮窗口权限被禁止了,要先去设置页面打开
  • 小米手机需要关闭miui优化

~仅供参考~

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读