简体   繁体   English

在模拟器中启动应用程序后,“React native run android”立即停止

[英]'React native run android' stop immediatelly after start the app in emulator

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. 我正在尝试测试我的Android应用程序,但是当我在设备启动时启动它并使用react-native run-android命令后立即停止而没有错误。

I got this: 我懂了:

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 }

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. 我收到提示但不总是,如果我继续尝试它有时运行正常,但我必须运行10-15次。 The SDK version is 25 and I followed the React Native Getting Started installation guide. SDK版本为25,我遵循React Native Getting Started安装指南。

  • OS: Fedora 24 操作系统:Fedora 24
  • React-native: 0.42.0 React-native:0.42.0

UPDATE: 更新:

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

UPDATE 2: 更新2:

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. 似乎问题出现了,因为远程调试器在设备上打开并且它连接到:8081端口上的远程调试器,并且adb想要通过:8081为旧的远程调试创建一个新的服务器用于移动应用程序仍占用:8081端口,因此不允许创建新端口。 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. 我不确定这可能是问题所在。

i was having the same problem in ubuntu what worked for me is that i closed terminal removed my device from usb restarted. 我在ubuntu遇到同样的问题对我有用的是我关闭终端从usb重新启动我的设备。 first of all would suggest you add these lines inside your packages.json replace scripts with this 首先,建议你在packages.json中添加这些行来替换脚本

"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

after that 之后

npm run android 

It will run app in device as well as start-reset cache.Let me know if it helps. 它将在设备中运行应用程序以及启动重置缓存。让我知道它是否有帮助。

Sometimes adding 有时添加

adb reverse tcp:8081

before running npm run android does the trick I will recommend you to enable Gradle daemon it really makes your build faster. 在运行npm之前运行android的技巧我会建议你启用Gradle守护进程它真的让你的构建更快。 To enable it goto android->gradle.properties and inside that file write 要启用它转到android-> gradle.properties并在该文件内写

org.gradle.daemon=true

I had the same issue and problem is described here port already in use . 我有同样的问题,这里描述的问题端口已经在使用中 So just kill the process occupying the port. 所以只需杀死占用端口的进程。

sudo lsof -i :8081

kill -9 <PID>

In my case just cleaning the cache was helpful: 在我的情况下,只是清理缓存是有帮助的:

npm cache clean --force  
.android/gradlew clean

In my case when there was no error at all and build was successful, the builder was exiting after the build and app crashed. 在我的情况下,当没有任何错误并且构建成功时,构建器在构建和应用程序崩溃后退出。

Here is you solve it, after it exits, just type 这是你解决它,退出后,只需键入

yarn start

Your react-native should be up & running. 你的反应原生应该正常运行。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在模拟器中启动应用程序后,“ React native run android”停止 - 'React native run android' stops just after start the app in emulator React Native Android App拒绝在模拟器上运行 - React Native android App refused to run on Emulator 无法在 Android 模拟器上运行 React-Native 应用程序 - Windows - Cannot run React-Native app on Android emulator - Windows 无法在 Android 模拟器中运行反应本机应用程序 - 使用 EXPO cli - Not able to run react native app in Android Emulator - using EXPO cli npx react-native run-android 不启动模拟器,如果模拟器正在运行则不运行 - npx react-native run-android doesn't start emulator and doesn't run if emulator is running React-native 0.60.x 应用程序立即崩溃 - React-native 0.60.x app crash immediatelly 反应在模拟器中本机运行android会抛出错误 - react native run android in emulator throws erro Android Emulator无法在react-native run-android中运行我的应用 - Android Emulator does not run my app in react-native run-android 无法在 Android 模拟器上启动本机应用程序(任务:app:checkDebugAarMetadata FAILED) - Fails to start react native app on Android emulator (Task :app:checkDebugAarMetadata FAILED) React Native 应用程序在 android 模拟器上不断关闭 - React Native app keeps closing on android emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM