React Native开发环境配置

手机系统:Android
开发环境:Mac

首先要确认安装以下工具:

Homebrev

安装:

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

查看:

$ brew -v
Homebrew 0.9.9 (git revision 95863; last commit 2016-09-07)
Homebrew/homebrew-core (git revision deaf3; last commit 2016-09-07)

node

安装:

brew install node

查看:

$ node -v
v6.5.0

watchman

安装:

brew install watchman

查看:

$ watchman -v
4.6.0

React Native command line

安装:

sudo npm install -g react-native-cli

查看:

$ react-native -v
react-native-cli: 1.0.0
react-native: 0.32.1

打开模拟器,创建&运行测试APP:

react-native init AwesomeProject
cd AwesomeProject
react-native run-android

遇到提示:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/caoyuhong/AwesomeProject/android/app/build.gradle' line: 110

* What went wrong:
A problem occurred evaluating project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

解决方案:

在工程目录/android下,创建文件local.properties,文件中写入自己Android SDK位置

sdk.dir=/Applications/Develop/adt-bundle-mac-x86_64-20140702/sdk

再次输入react-native run-android
如果build成功,会出现以下信息:

Installing APK 'app-debug.apk' on 'Google Nexus 5 - 5.0.0 - API 21 - 1080x1920 - 5.0'
Installed on 1 device.

BUILD SUCCESSFUL

Total time: 15.432 secs

如果APP没有自动启动,看到如下信息:

/bin/sh: adb: command not found
Starting the app (adb shell am start -n com.awesomeproject/.MainActivity...

则需要配置adb环境变量:

首先查看用户目录下是否有.bash_profile文件,如果没有,自己创建一个

cd ~
a | grep .bash_profile

修改.bash_profile的PATH,

vim .bash_profile

在:${PATH}前,其他环境变量后,加上adb目录。Mac上环境变量和Linux一样,是用:分隔的

PATH="(其他的环境变量):/Applications/Develop/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/:${PATH}"

修改后保存配置

source .bash_profile

重新运行run命令,
查看模拟器:

等待一下,出现如下画面,说明配置成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值