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

查看:24
本文介绍了在模拟器中启动应用程序后,“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 并且有人说我正在加载依赖图...错误打包程序无法侦听端口 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 重新启动了我的设备.首先建议你在你的packages.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 run 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天全站免登陆