在android模拟器上运行react-native

问题描述 投票:26回答:6

我尝试在我的mac上运行genymotion android模拟器上的react-native app。当我写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模拟器上运行app时,它会得到相同的错误,但没有error: closed

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

android-emulator react-native adb genymotion react-native-android
6个回答
35
投票

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

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

Configure Required SDKs Configure Required SDKs

  1. 如果您已经安装了它,那么您必须更新以下SDK: Android SDK Tool(更新至最新版本) Android SDK Platform-tools(更新至最新版本) Android SDK Build-tools(更新至最新版本) 在Android Support Repository文件夹下的Extra(更新到最新版本)
  2. 您必须至少安装与安装的Android APIAndroid SDK Build-tools版本相同的版本Android SDK Platform-tools,如上面的Configure Required SDKs图所示。

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


7
投票

我每次或者在物理设备上都有类似的问题从android studio运行模拟器。相反,你可以从命令行快速运行android模拟器,

android avd

模拟器运行后,您可以使用adb devices查看模拟器是否显示。然后你可以简单地使用react-native run-android在模拟器上运行应用程序。

确保安装了平台工具才能使用adb。或者你可以使用

brew install android-platform-tools

2
投票

碰巧我,我有一个运行旧项目的打包器实例(我像往常一样运行react-native start)。我使用的是Ubuntu 14.04。所以我做的是停止该实例并转到我的项目文件夹,并在两个不同的控制台选项卡中分别运行这两个命令:

npm start #here I used to run react-native start
react-native run-android

npm start在我的package.json中定义为:

"start": "node_modules/react-native/packager/packager.sh"

我不知道是否存在一种令人困惑的反应本地化的东西,但这就是诀窍。


1
投票

有类似的问题。我更新了我的Genymotion和我的android SDK / libraries / dependencies,一切似乎都有效。要更新我的SDK,我使用了android sdk manager {ANDROID_SDK_FOLDER}/tools/android sdk


1
投票

在Windows 10和Android Studio上,您可以在Android Studio中将“文件” - >“设置”置于“设置”中,然后转到“外观和行为” - >“系统设置” - >“Android SDK”。在选项卡“SDK工具”中激活:

  • “Android SDK Build-Tools ..”
  • “Android模拟器”
  • “Android SDK平台工具”
  • “Android SDK工具”

如果全部安装完毕,那么您可以使用“工具” - >“Android” - >“AVD Manager”在Android Studio中启动模拟器。如果模拟器运行你可以尝试“react-native run-android”


1
投票

在我的情况下,这发生了,因为android / gradlew文件没有执行权限。一旦被授予,这工作正常

© www.soinside.com 2019 - 2024. All rights reserved.