在模拟器中启动应用后,"React native run android"立即停止 [英] 'React native run android' stop immediatelly after start the app in emulator

查看:280
本文介绍了在模拟器中启动应用后,"React native run android"立即停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试我的Android应用程序,但是当我在设备上启动react-native run-android命令启动它时,它会立即停止且没有错误.

I'm trying to test my Android application but when I start it with react-native run-android command after it is start on the device inmediatelly stop without error.

我知道了:

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
Running adb -s emulator-5556 reverse tcp:8081 tcp:8081
Starting the app on emulator-5556 (adb -s emulator-5556 shell am start -n com.app/.MainActivity)...
Starting: Intent { cmp=com.app/.MainActivity }

返回提示但并非总是如此后,如果继续尝试,它有时会正常运行,但是我必须运行10到15次. SDK版本为25,我遵循了React Native入门安装指南.

After I get back the prompt but not always, if I keep on try it is sometimes running properly, but I have to run this 10-15 times. The SDK version is 25 and I followed the React Native Getting Started installation guide.

  • 操作系统:Fedora 24
  • 本机:0.42.0

更新:

我尝试了react-native start,有人说我Loading dependency graph... ERROR Packager can't listen on port 8081,但是我不明白为什么上一个命令没有对我说.在这种情况下,我可以使用--port 9000更改端口,但是在react-native run-android命令中没有找到任何其他标志.

I tryed out with react-native start and it was said for me Loading dependency graph... ERROR Packager can't listen on port 8081 but I don't understand why the previous command didn't said it for me. In this case I can change the port with the --port 9000, but I didn't found any other flag for the in the react-native run-android command.

更新2:

似乎发生了此问题,因为远程调试器已在设备上打开,并且已通过:8081端口连接到远程调试器,而adb希望通过:8081在一段时间内为移动应用创建新服务器.旧的远程调试仍然占据:8081端口,因此不允许创建新端口.我关闭了远程调试器,它运行正常.我不确定这是否是问题所在.

It seems the problem occured because the remote debugger switched on on the device and it's connected to the remote debugger on the :8081 port and the adb wanted to create a new server for the mobile app through the :8081 for a while the old remote debug is still occupy the :8081 port, so it wasn't allow to create a new one. I switched off the remote debugger and it is running without problem. I'm not sure about that it's possible it was the problem.

推荐答案

我在ubuntu中遇到了同样的问题,对我有用的是关闭的终端从重新启动的usb中删除了我的设备.首先建议您将这些行添加到package.json中,用此替换脚本

i was having the same problem in ubuntu what worked for me is that i closed terminal removed my device from usb restarted. first of all would suggest you add these lines inside your packages.json replace scripts with this

"scripts": {
"prepare-repository": "npm i -g react-native-cli yarn;yarn install; react- native link",
"emulator": "emulator -avd Nexus5V6L23_x86_64 -scale 1.0",
"install": "react-native run-android",
"start": "react-native start --reset-cache",
"android": "npm run install && npm run start",
"clean": "watchman watch-del-all && npm cache clean && cd android && ./gradlew clean && cd ..",
"test": "jest"
}

之后,将其保存,然后转到创建项目的文件夹.可以说我的住所/工作区/演示.在该运行脚本中

After that save it and then go to the folder where u created project. lets say mine home/workspace/demo. Inside that run script

 npm run clean //this will clear all cache

之后

npm run android 

它将在设备以及启动重置缓存中运行应用程序.让我知道它是否有帮助.

It will run app in device as well as start-reset cache.Let me know if it helps.

有时会添加

adb reverse tcp:8081

在运行npm之前,运行android可以达到目的 我将建议您启用Gradle守护程序,它确实可以使您的构建速度更快.要启用它,请转到android-> gradle.properties并在该文件中写入

before running npm run android does the trick I will recommend you to enable Gradle daemon it really makes your build faster. To enable it goto android->gradle.properties and inside that file write

org.gradle.daemon=true

这篇关于在模拟器中启动应用后,"React native run android"立即停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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