在 android 模拟器上运行 react-native

新手上路,请多包涵

我尝试在我的 mac 上的 genymotion android 模拟器上运行 react-native 应用程序。当我写 react-native run-android 它得到

Running /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
error: closed
Could not run adb reverse: Command failed: /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && ./gradlew installDebug...
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/android-setup.html
MacBook-Pro-MacBook:ART-CarefulPeople macbook$

然后我试过了:

  1. react-native start
  2. react-native run-android

同样的结果。

然后我试过了:

  1. react-native bundle --entry-file index.android.js --platform android --bundle-output android/app/src/main/assets/index.android.bundle

  2. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

  3. react-native run-android

同样的结果。

我试过了 adb reverse tcp:8081 tcp:8081 它说 error: closed

当我尝试在 android-sdk 模拟器上运行应用程序时,它会出现上述相同的错误,但没有 error: closed

从 android studio 我可以运行这个应用程序,它适用于 genymotion。请告诉我,我应该怎么做才能在 android 模拟器上运行我的应用程序?

原文由 alborozd 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1k
2 个回答

我有一个类似的问题,在花了这么多时间和大量搜索这个问题之后,唯一对我有用的技巧:

  1. 请安装所需的 SDK,如图所示

Configure Required SDKs 配置所需的 SDK

  1. 如果您已经安装了它,那么您必须更新以下 SDK:
    • Android SDK Tool (更新到最新版本)
    • Android SDK Platform-tools (更新到最新版本)
    • Android SDK Build-tools (更新到最新版本)
    • Android Support Repository Extra 文件夹下(更新到最新版本)
  2. You Must have at least Installed the Same version Android API as the installed Android SDK Build-tools & Android SDK Platform-tools version as shown in the Configure Required SDKs figure above.

注意: 在 React-native 官方文档中列为 SDK 要求的 Support Libraries 本地 Maven 存储库现在在 SDK Manager 中命名为 Android Support Repository。

原文由 Rizwan Jamal 发布,翻译遵循 CC BY-SA 3.0 许可协议

有类似的问题。我更新了我的 Genymotion 和我的 android SDK/库/依赖项,似乎一切正常。为了更新我的 SDK,我使用了 android sdk manager {ANDROID_SDK_FOLDER}/tools/android sdk

原文由 Vincent Nguyen 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题