sayi.github.com icon indicating copy to clipboard operation
sayi.github.com copied to clipboard

React Native 开发实践

Open Sayi opened this issue 8 years ago • 0 comments

搭建环境

  1. 安装包管理器Homebrew,通过brew安装包
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.安装node、watchman

brew install node
brew install watchman

3.可选:nrm切换npm源 4.安装react native cli

npm install -g react-native-cli

5.管理android studio 安装Android SDK Build-Tools 23.0.1,并且确保android6.0以下的组件被安装:

Google APIs Android SDK Platform 23 Intel x86 Atom_64 System Image Google APIs Intel x86 Atom_64 System Image

6.配置ANDROID_HOME环境变量

vi ~/.profile
export ANDROID_HOME=/**/sdk
source   ~/.profile

Hello world

  1. 初始化项目
react-native init AwesomeProject

2.运行、调试项目 前提:在允许调试的真机上运行项目,在Building and installing the app on the device (cd android && ./gradlew installDebug)...这一步时会去下载gradle,经常容易超时,我们修改项目目录下android/gradle/wrapper/gradle-wrapper.properties文件distributionUrl=gradle-3.1-bin.zip,并且将gradle包拷贝到该目录下,接下来就可以运行项目了

cd AwesomeProject
react-native run-android

至此,在真机上已经可以看到运行的app了,本地浏览器访问http://127.0.0.1:8081/可以看到服务已经启动,支持代码实时修改,通过reload JS应用变化。 若需要重新连接真机,进入adt查看已连接的真机adb devices,输入以下命令访问开发服务器。

adb reverse tcp:8081 tcp:8081

打包APK,发布应用

Sayi avatar Jun 04 '17 10:06 Sayi