0

网上有很多关于这个错误的帖子。我的情况是我有时可以建立连接,但大多数时候都失败了。这是失败时的错误:

PS C:\d\code\js\chatapp> react-native run-android
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
27 actionable tasks: 1 executed, 26 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

这是成功时的消息:

PS C:\d\code\js\chatapp> react-native run-android
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'MHA-L29 - 8.0.0' for app:debug
Installed on 1 device.


BUILD SUCCESSFUL in 6s
27 actionable tasks: 1 executed, 26 up-to-date
'adb' is not recognized as an internal or external command,
operable program or batch file.
Starting the app (c:\AppData\Local\Android\Sdk/platform-tools/adb shell am start -n com.chatapp/com.chatapp.MainActivity...
Starting: Intent { cmp=com.chatapp/.MainActivity }

我没有很好的解释为什么有时它确实有效而其他时候却没有。在每个react-native run andrioid,USB Debugging在 Mate 9 上启用。

4

4 回答 4

1

当我连接的电话有锁定屏幕时,我也会发生这种情况。当您尝试跑步时,请确保手机处于“活动状态”。在运行 react-native run-android 之前,您可以使用“adb devices”命令列出所有连接的设备。确保一次只有一个(没有模拟器运行)。我可以推荐的最后一件事是更新 React Native。他们在每个版本的改进上都做得很好,而且您可能永远不会在最新版本中再次看到此错误。祝你好运!

于 2019-01-25T10:28:18.810 回答
1

我有一个类似的问题,只是在这里发布了一个对我有用的解决方案 - https://stackoverflow.com/a/67566428/10392546

我遇到了一个类似的问题,不确定你是否能解决它,但是我在寻找解决方案时遇到了这篇文章,上面的解决方案对我不起作用。

我发现的一个解决方案是从 google 安装 android-emulator-m1-preview,启动它而不是从 Android Studio 内部启动模拟器。它几乎令人讨厌,它原来是一个多么简单的问题要解决。

在尝试不同的解决方案 12 多个小时后看到构建成功真是太好了。

于 2021-05-17T08:42:13.463 回答
0

我的项目有这个问题。我已经尝试了很多方法来解决这个问题,并且我在 stackoverflow、github、博客文章中有很多指南。但是我在这个过程中犯了一个错误。因此,请确保您在调试期间进行操作。

  1. cd android && ./gradlew clean && ./gradlew :app:bundleRelease

  2. 确保在每个动作中擦除模拟器中的数据

  3. 如果您正在尝试使用外部设备,请确保它在线或解锁屏幕。

于 2021-05-24T01:35:40.560 回答
0

尝试从手机中卸载该软件包。有时,这些数据会缓存在您的手机内存中。您可以使用以下命令。

  1. 列出连接到您计算机的 adb 设备。前往项目根目录中的终端并运行adb devices. 这将列出所有连接的设备。您的结果将如下所示;

$ adb devices List of devices attached 047292599G105335 device
  1. 然后运行 adb -s <your_device_key> uninstall <your_package_name>。<your_device_key> 在这种情况下是 is047292599G105335并且包名称看起来像com.appname,都没有方括号。

    所以就我而言,它看起来像 adb -s 047292599G105335 uninstall com.appname

  2. 现在再次运行您的项目react-native run-android

于 2021-10-28T06:56:52.107 回答