我正在try 测试我的Android应用程序,但当我在设备上启动后用react-native run-android命令启动它时,会立即停止,不会出现错误.

我明白了:

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 }

在我返回提示后,如果我继续try ,它有时会正常运行,但我必须运行10-15次.SDK版本是25,我遵循了React Native Getting Started installation guide.

  • OS:Fedora 24
  • react 本机:0.42.0

UPDATE:

我试了react-native start次,结果说是Loading dependency graph... ERROR Packager can't listen on port 8081次,但我不明白为什么之前的命令没有说是Loading dependency graph... ERROR Packager can't listen on port 8081次.在本例中,我可以使用--port 9000更改端口,但在react-native run-android命令中,我没有找到用于的任何其他标志.

UPDATE 2:

出现问题的原因似乎是远程调试器在设备上打开,并通过:8081端口连接到远程调试器,而adb想通过:8081为移动应用程序创建一个新服务器,而旧的远程调试仍占用:8081端口,因此不允许创建新服务器.我关闭了远程调试器,它运行正常.我不确定这是否是问题所在.

推荐答案

我在ubuntu中也遇到了同样的问题,但对我有效的是,我关闭了终端,从usb重启中删除了我的设备.首先,我建议你在你的软件包中添加这些行.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"
}

然后保存它,然后转到你创建项目的文件夹.比如我的家/工作区/演示.在运行脚本中

 npm run clean //this will clear all cache

之后

npm run android 

它将在设备中运行应用程序,并启动重置缓存.如果有帮助,请告诉我.

有时添加

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. To enable it goto android->gradle.properties and inside that file write

org.gradle.daemon=true

React-native相关问答推荐

什么是 expoClientId?

应用管理

在 ReactNative 中调用 RCTDeviceEventEmitter.emit 时出错

Error: Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component stack

React Native - 动画宽度缩小

React Native 的 Firebase 初始错误(无法读取未定义的属性getItem)

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

请求无法完成,因为您已超出配额

你能在 Ubuntu 上构建 React Native 应用程序(Android 应用程序)吗?

如何在 React Native 中使用断点进行调试

如何解决react-navigation 问题:Animated: `useNativeDriver` is not supported because the native animated module is missing.?

使用离线包在 iOS 设备上运行 react-native 应用程序

自定义原生基础的选项卡

React native + redux-persist:如何忽略键(黑名单)?

如何在 Expo 和 React Native 中使用绝对路径导入?

> 任务 :app:checkDebugAarMetadata 在运行 react-native run-android 时失败

xcode 10错误:multiple commands produce

我们可以在 react webapp 和 react native 应用程序之间共享代码吗,并且可以在 react-native 生产环境中使用

React Native - 如何从推送通知中打开路由

如何在 react-native 中重叠