React-Native Android 学习笔记——1,配置环境

一,设备与环境

1,一台 mac

2,安装软件包管理器 Homebrew(中文)

终端里输入/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"进行安装。

3,安装 wget 或者 curl

wget,终端里输入brew install wget进行安装。
curl,终端里输入brew install curl进行安装。

4,安装 nvm (node版本管理器)

如果安装了 wget,终端输入wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash进行安装 nvm。

如果安装了 curl,终端输入curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bashÂ进行安装 nvm。

5,Android SDK

这个不用多说了,相信大家都会的。顺便把 Android SDK 配置到环境变量。

如果你没有 Android SDK,也可以通过终端输入brew install android-sdk

二,安装和初始react-native demo

终端输入npm install -g react-native-cli安装 react-native。

如果显示EACCES: permission denied,用超级权限再次执行一下上面的指令。反正我是没遇到。

进入到你要创建 demo 的目录,终端输入cd 你得文件路径.
终端输入react-native init AwesomeProject,初始 AwesomeProject 。

终端输入cd AwesomeProject

终端输入react-native run-android可以直接运行 node 服务并编译运行 Android 项目,直至安装到手机。

如果界面报错提示如下:

Unable to download JS bundle
com.facebook.react.devsupport.DebugServerException: Could not connect to development server.

URL: http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false

Try the following to fix the issue:
• Ensure that the packager server is running
• Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices
• If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device
• If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081
at com.facebook.react.devsupport.DevServerHelper$1.onFailure(DevServerHelper.java:203)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:175)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

一般在终端输入adb reverse tcp:8081 tcp:8081即可解决,其他请详细看 log。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值