ReactNative.MacOs Android环境搭建

搭建过程

Homebrew安装

  1. mac 终端输入命令:/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

  2. 出现问题,报错log如下:
    error: RPC failed; curl 18 transfer closed with outstanding read data remaining
    fatal: The remote end hung up unexpectedly
    fatal: 过早的文件结束符(EOF)
    fatal: index-pack 失败
    Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

  3. 解决过程:
    注:Homebrew用来安装Node和WatchMan,
    a. 先输入命令 curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install获取安装配置文件,再vim brew_install修改其中的
    BREW_REPO = “https://github.com/Homebrew/brew”.freeze
    为BREW_REPO = “git://mirrors.ustc.edu.cn/brew.git”.freeze;
    b. 输入/usr/bin/ruby ~/brew_install安装HomeBrew;

Node和WatchMan安装

  1. HomeBrew安装完成后,输入brew install node安装Node;

  2. 再输入命令brew install watchman安装WatchMan;

    安装完 Node 后建议设置 npm 镜像以加速后面的过程:
    npm config set registry https://registry.npm.taobao.org --global
    npm config set disturl https://npm.taobao.org/dist --global

    Yarn是 Facebook 提供的替代 npm 的工具,可以加速 node 模块的下载。React Native 的命令行工具用于执行创建、初始化、更新项目、运行打包服务(packager)等任务。

    npm install -g yarn react-native-cli
    安装完 yarn 后同理也要设置镜像源:

    yarn config set registry https://registry.npm.taobao.org --global
    yarn config set disturl https://npm.taobao.org/dist --global
    安装完 yarn 之后就可以用 yarn 代替 npm 了,例如用yarn代替npm install命 令,用yarn add 某第三方库名代替npm install 某第三方库名。

Android环境搭配

本人mac上已经配置好,不作赘述

RN工程创建运行

  1. 创建命令:react-native init AwesomeProject
  2. 运行命令:cd AwesomeProject
    react-native run-android

遇到问题:

  1. What went wrong:
    A problem occurred configuring project ‘:app’.

SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project’s local properties file at ‘/Users/Jack.peng/AwesomeProject/android/local.properties’.

解决方案:/Users/Jack.peng/AwesomeProject/android/下新建local.properties,配置好sdk路径sdk.dir=/Users/Jack.peng/Library/Android/sdk

  1. What went wrong:
    A problem occurred configuring project ‘:app’.

Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
platforms;android-28 Android SDK Platform 28
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: /Users/Jack.peng/Library/Android/sdk
上边log显示build-tools sdk platform缺失

解决方案:AS中打开SDKManager,把对应的Build-Tools 28.0.3 、SDK Platform 28下载下来

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值