加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 03:37:07 所属栏目:百科 来源:网络整理
导读:一,设备与环境 1,一台 mac 2,安装软件包管理器 Homebrew(中文) 终端里输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 进行安装。 3,安装 wget 或者 curl wget,终端里输入 brew install wge

一,设备与环境

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。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读