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下載下來

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章