mac + react-native environment to build

The main reference  https://reactnative.cn/docs/getting-started.html  REACT-Native Chinese network

 

IOS version

1, Node v10 above, Watchman and React Native command-line tool, and Xcode

 

Brew install the tool, it is easy to install later, the first installation may be slower, be patient. . .

-e Ruby " $ (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) " 

After installation, due to the default of foreign mirroring slower, have to modify the source address for domestic of.

 

1)替换brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git



2)替换homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

 

Installation node

BREW install the Node where you may be prompted to follow dependencies, follow the instructions given to install

 

Installation watchman

brew  install watchman
Also modify the mirrored address 

npm config the SET Registry HTTPS: // registry.npm.taobao.org
 
--global npm config the SET disturl HTTPS: // npm.taobao.org/dist --global

 

2,  React Native command-line tools (Native-REACT-CLI), the Yarn alternative tool Facebook npm provided, after installing npm yarn can be used instead of yarn, for example yarninstead of npm installa command, by yarn add 某第三方库名instead ofnpm install 某第三方库名

npm install -g yarn react-native-cli
Modify Mirror address
yarn config set registry https://registry.npm.taobao.org--global  yarn config set disturl https://npm.taobao.org/dist --global 

 

3, React Native current need Xcode  version 9.4 or later, APP Store to download

 

4, initialization project

react-native init AwesomeProject

 

5, compile and run React Native Application

cd AwesomeProject

react-native run-ios
注意: 此步骤可能会提示xcrun: error: unable to find utility "instruments", not a developer tool or in PATH错误,

解决方法:

1sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/ 命令即可解决此问题



可能会提示Could not find iPhone 6 simulator--

解决方法:

1、react-native run-ios --simulator="iPhone 6",运行时指定启动版本

2 、打开项目文件node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

然后,Check if your device version is correct, e.g: in line 29 console.log(version) 。在文件30行,对比是否是这个条件:Compare it with condition in line 30: if (version.indexOf('iOS') !== 0) {

  注释掉的是version.indexOf('iOS') !== 0,然后替换成

if (version.indexOf('iOS') !== 0 && !version.includes('iOS')) {
continue;
}

 

6、 再重新执行react-native run-ios --simulator="iPhone 6" 命令,如果成功就可以看到手机模拟运行的效果了

 

 

android版

1、下载adroid studio https://developer.android.google.cn/studio/

2、按照https://reactnative.cn/docs/getting-started.html上面给出的安装步骤依次操作即可,上面说是要翻墙,但好像不翻也可以!!!

需要注意的地方是在运行项目的时候,得先新建模拟器,不然在react-native run-android执行时,

会出现installDebug FAILED,网上说修改gradle版本,还有改distributionURL参数。本人都没改,在Android studio 新建好模拟器即可!!!

 

至此,以上就是本人在Mac 10.14.6 搭建react-native的过程及其过程中所遇到的问题,给小伙伴们提供个参考吧。

Guess you like

Origin www.cnblogs.com/codechange/p/11415280.html