Running React Native Android on device

别等时光非礼了梦想. 提交于 2019-12-20 15:29:50

问题


I followed this official help page and also consulted this previous SO question.

But I still don't know what is wrong here.

Let's take step by step:

  1. Ensure the package server is running. From the screenshot, you can see the command I typed "react-native run-android" and the reponse "Starting JS server..."

  2. Ensure your device is connected... Yes, Vysor sees my device. Wee see Vysor showing the app running in the screenshot.

  3. ...USB enabled Yes, the app is running, that's why we see the red error screen, but it's the app running nevertheless.

  4. Run "adb reverse tcp:8081 tcp:8081" Yes, the screenshot shows that I ran the command.

  5. Device and port... Yes, did that too. See next screenshot

What am I still doing wrong? How can I make it work?


回答1:


  • Run npm run start in one console window to start the react-native development server.
  • Then open a separate console window to run react-native run-android.

I sometimes ran into problems if I don't start the development server in a separate console window.

Further notes:

  • Make sure that your device is shown if you run $ adb devices in your console.
  • Note that adb reverse tcp:8081 tcp:8081 only works for Android versions 5.0 and up.



回答2:


Could you provide us the screenshot of React Packager - run 'npm start' before doing 'react-native run-android'.

I am using Visual Studio Code with React Native tools extension that takes care of port forwarding, deploying the app to device/emulator and it works okay - I get similar screen at start, but clicking 'Reload' takes care of it.




回答3:


I was stuck at this exact step and finally I checked my firewall and lo and behold it was blocking the connection from my device to my computer. I unblocked it and after a reload everything worked.




回答4:


Try

adb reverse tcp:8081 tcp:8081
react-native start --reset-cache
react-native run-android


来源:https://stackoverflow.com/questions/38410756/running-react-native-android-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!