react native 环境搭建步骤如下:
1、安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
2、安装node
brew install node
3、安装react native
npm install -g react-native-cli
4、安装Xcode
去appstore下载安装
5、安装watchman
brew install watchman
6、新建项目
react-native init AwesomeProject
7、跑起来
cd AwesomeProject
react-native run-ios
一、iosAPP打开闪退
1、重新安装node,报错误:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pkg-config
2、把node卸载干净
sudo npm uninstall npm -g
sudo make uninstall
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
ls -laF /usr/local/{lib/node{,/.npm},bin,share/man} | grep npm
find /usr/local/{lib/node,bin} -exec grep -l npm \{\} \; ;
重新执行brew install node。
成功。
安全起见,执行:
sudo chown -R `whoami` /usr/local
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
add the following line to your ~/.bash_profile:
export PATH="$HOME/.npm-packages/bin:$PATH"
source ~/.bash_profile或者重启电脑
现在,您可以重新安装你需要任何包,没有任何问题的。
二、执行brew install watchman时,控制台报错:
Error: You must `brew link autoconf` before watchman can be installed
解决方案:
在终端依次输入以下命令
1、brew uninstall watchman
2、sudo chown -R `whoami` /usr/local
3、brew link --overwrite autoconf
4、brew install watchman
控制台继续报错:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pcre-config
Target /usr/local/bin/pcre-config
already exists. You may want to remove it:
rm '/usr/local/bin/pcre-config'
解决方案:
在终端依次输入以下命令
1、brew uninstall watchman
2、sudo chown -R `whoami` /usr/local
3、brew link --overwrite pcre
4、brew install watchman
成功。
三、重新按步骤依次执行,哈哈~成功~