mac react-native 环境搭建与运行

来源:互联网 发布:免费erp管理系统 知乎 编辑:程序博客网 时间:2024/06/01 21:07

早期,从事android 开发,最先接触的是Cordova的混合开发,最近由于苹果热更新问题,下架app,为了解决这个问题,发现对于react-native 的热更新,还没有下架的应用。

  • 一是为了统一兼容 android 与ios 开发模式
  • 二是需求改版,一边解决,采用现在我所说的react-native 框架,经过集成开发环境对比,发现。两者在配置发面,命令非常类似,这里不在对原有的进行解说。
    下面我来说怎么配置。

首先打开这个链接 http://reactnative.cn/docs/0.46/getting-started.html#content
根据电脑系统,与开发的平台,选择对应的平台。我这个电脑现在是mac os系统,所以选择了macos andorid ,

接下来就是打开终端一步步按照文档输命令了,在此我先说说,要安装哪些配置。
首先要安装 homebrew ,要用到brew 这个命令,来安装nvm,nvm里有这个命令npm,然后就要安装node.js 接下来就是安装命令行工具(react-native-cli),推荐安装的工具watchman和flow,js开发工具Atom ,WebStorm或Sublime Text来编写React Native应用。


android 方面,要注意Android Support Repository 和Android SDK Build-Tools 23.0.1必须大于这个版本

homebrew 可以参考这个网站:https://www.brew.sh1)复制下面一段命令,在终端中执行:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"2)修改当前用户这个目录下所有文件权限。sudo chown -R `whoami` /usr/local3)安装 nodebrew install node4)为了创建项目不卡顿,这时链接的国内镜像进行配置:   vi ~/.npmrc 加入下面内容:       resgistry=http://registry.npm.taobao.org********************5)命令行工具(react-native-cli)   npm install -g yarn react-native-cli6)brew install watchman7)brew install flow

以上都是主要的一些安装,对于安装android 平台运行环境,见:
http://reactnative.cn/docs/0.46/getting-started.html#content或https://facebook.github.io/react-native/docs/getting-started.html
,以便深入学习。

这里要说明一种错误,当我们打开androidStudio 时,运行react-native android平台项目时,会报错:/************************************************/unable to load script from assets 'index.android bundle'  ,make sure your bundle is packaged correctly or youu're runing a packager server/***********************************************/对于这个的处理方式是:1)在  android/app/src/main 目录下创建一个  assets空文件夹;2)打开终端执行:react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/  
原创粉丝点击