2017-11-28
本指南归纳了基本的React Native环境安装方法和常见问题
choco install python2
choco install adb
npm install -g react-native-cli
sudo apt-get install python2
sudo apt-get install adb
sudo npm install -g react-native-cli
sudo yum install python2
sudo yum install adb
sudo npm install -g react-native-cli
只有没有安装过node的机器才需要进行这一步
choco install nodejs.install
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
npm install -g yarn
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
sudo apt-get install nodejs.install
sudo npm config set registry https://registry.npm.taobao.org --global
sudo npm config set disturl https://npm.taobao.org/dist --global
sudo npm install -g yarn
sudo yarn config set registry https://registry.npm.taobao.org --global
sudo yarn config set disturl https://npm.taobao.org/dist --global
sudo yum install nodejs.install
sudo npm config set registry https://registry.npm.taobao.org --global
sudo npm config set disturl https://npm.taobao.org/dist --global
sudo npm install -g yarn
sudo yarn config set registry https://registry.npm.taobao.org --global
sudo yarn config set disturl https://npm.taobao.org/dist --global
(if not exist "%USERPROFILE%/.gradle" mkdir "%USERPROFILE%/.gradle") && (echo org.gradle.daemon=true >> "%USERPROFILE%/.gradle/gradle.properties")
SDK 和棉花糖的API 23是默认安装的
事实上在 Android Studio
编译运行时,所依赖的组件会自动安装,但是我们用RN最好手动将需要的组件安装好
默认会安装
Build-Tools 23.0.3
等,如果不使用React-Native
之外的其他版本可以卸载
注意!!! 几乎一定会有安装失败的包,观察错误信息重新安装即可。重复多次这个步骤直到所有的依赖项都安装完成。
ANDROID_HOME
变量PATH
变量任选其一,也可以用Android Studio自带的模拟器
react-native init someProject
cd someProject
react-native run-android
adb logcat *:S ReactNative:V ReactNativeJS:V
adb devices
同时包括模拟器在内,你应该只链接一个设备
react-native run-android
用reverse命令可以直接用默认设置链接服务器
adb reverse tcp:8081 tcp:8081
不光是安卓版本,其他玄学问题也有可能导致连接失败,尝试摇晃手机reload JS
来确定已经连接成功
先获得调试机的局域网ip
ipconfig
获得ip和端口号之后,执行以下步骤
react-native run-android
都可以)Dev Settings
Debug server host for device
Reload JS
echo "anything" >> README.md
git init
git add .
git remote add origin https://github.com/somewhere.git
git push -u origin master