oHeHeHou的专栏

我是菜鸟 请多指教

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命令,
查看模拟器:

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

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/oHeHeHou/article/details/52486074
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭