React Native的"hello world"快速入门:“无法连接到开发服务器" [英] React Native 'hello world' quick start: "could not connect to development server"

查看:79
本文介绍了React Native的"hello world"快速入门:“无法连接到开发服务器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做本机的"hello world",并且在我的android上使用usb调试.

I'm trying to do the react native 'hello world', and I'm using usb debugging on my android.

我先运行了 react-native run-android ,然后又运行了 react-native start .

I ran react-native run-android, then react-native start.

我可以在 localhost 中查看js文件,但手机上显示无法连接到开发服务器"消息.

I can view the js file in localhost, but get 'could not connect to development server' message on my phone.

我按照说明运行了 adb reverse tcp:8081 tcp:8081 ,然后意识到该命令不存在,所以我运行了 adb forward tcp:8081 tcp:8081 代替.

I followed the instructions to run adb reverse tcp:8081 tcp:8081, then realized that command doesn't exist, so I ran adb forward tcp:8081 tcp:8081 instead.

仍然没有运气.使用react-native@0.22.0,Ubuntu 14.04.我的手机是Android 6.0.1上的nexus 5.

Still no luck. Using react-native@0.22.0, ubuntu 14.04. My phone is nexus 5 on android 6.0.1.

如何允许我的手机访问 localhost ?

How can I allow my phone to access my localhost?

顺便说一句,它可以在wifi上工作,但是我想让它在usb上工作.

By the way, it is working over wifi, but I'd like to get it working over usb.

推荐答案

还有另一种情况,当我忘记运行 react-native start 命令时,此错误发生在我身上.当我开始新项目时,通常会在此处中执行步骤.简而言之,步骤如下(在我的情况下为Android):

Just another scenario, this error happened to me when I forgot to run react-native start command. I usually follow the steps here when I start new project. The steps in a nutshell are as follows (Android in my case):

  • 启动Android Studio-> AVD Manager->选择您的aVD,然后点击从操作开始
  • 在要创建新项目的目录内,打开命令行并运行:

  • Start Android Studio -> AVD Manager -> select your aVD and click Start from action
  • inside the directory where you want to create your new project, open your command line and run:

$ react-native init <Your new project name/it is also the registration name>
$ cd <the new directory you created>
$ react-native start  //This is the step that I forgot

  • 打开一个新的命令提示符,然后在同一目录(您刚创建的目录)中运行以下命令,以在AVD上启动该应用程序.

  • Open a new command prompt and run the following inside the same directory(you just created) to launch the app on your AVD.

    $ react-native run-android
    

  • 如果一切设置正确,您应该会很快在Android模拟器中看到新应用正在运行.

  • If everything is set up correctly, you should see your new app running in your Android emulator shortly.

    您将在项目主目录的index.android.js文件中找到最后一行,它使用与上面第一个命令相同的名称来表示App注册表

    You'll find in the file index.android.js in the home directory of your project, the last line contians the App registry using the same name you used in the first command above

    这篇关于React Native的"hello world"快速入门:“无法连接到开发服务器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆