问题
I try to run react-native app on genymotion android emulator on my mac.
When I write react-native run-android
It gets
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$
Then I've tried:
react-native start
react-native run-android
The same result.
Then I've tried:
react-native bundle --entry-file index.android.js --platform android --bundle-output android/app/src/main/assets/index.android.bundle
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
react-native run-android
The same result.
I've tried just adb reverse tcp:8081 tcp:8081
and it says error: closed
When I try to run app on android-sdk emulator it gets the same error above but without error: closed
.
From android studio I can run this app and it works on genymotion. Tell me please what should I do to run my app on android emulator?
回答1:
I had a similar problem, and after spending so much time and lots of searching about this issue the only trick worked for me:
- Please Install the Required SDKs as shown in this figure
Configure Required SDKs
- If You have already installed it, so you must have to update the following SDKs:
Android SDK Tool
(update it to latest version)Android SDK Platform-tools
(update it to latest version)Android SDK Build-tools
(update it to latest version)Android Support Repository
underExtra
folder (update it to latest version)
- You Must have at least Installed the Same version
Android API
as the installedAndroid SDK Build-tools
&Android SDK Platform-tools
version as shown in theConfigure Required SDKs
figure above.
Note: Local Maven repository for Support Libraries which is listed as the SDK requirement in the official docs of React-native is now named as Android Support Repository in the SDK Manager .
回答2:
I had similar issue running emulator from android studio everytime, or on a physical device. Instead, you can quickly run android emulator from command line,
android avd
Once the emulator is running, you can check with adb devices
if the emulator shows up.
Then you can simply use
react-native run-android
to run the app on the emulator.
Make sure you've platform tools installed to be able to use adb
. Or you can use
brew install android-platform-tools
回答3:
It happened to me that I had an instance of the packager running with an old project (I ran react-native start as usual). I was using Ubuntu 14.04. So what I did was to stop that instance and go to my project folder and in two different console tabs I ran these two commands separately:
npm start #here I used to run react-native start
react-native run-android
npm start is defined in my package.json as:
"start": "node_modules/react-native/packager/packager.sh"
I don't know if there is a sort of confusing stuff for react-native but that did the trick.
回答4:
Had a similar problem. I updated my Genymotion and my android SDK's/libraries/dependencies and all seemed to work. To update my SDK's I used android sdk manager {ANDROID_SDK_FOLDER}/tools/android sdk
回答5:
On Windows 10 and Android Studio you kann go in Android Studio to "File"->"Settings" in Settings then to "Appearance & Behavior" -> "System Settings" -> "Android SDK". In the Tab "SDK Tools" active:
- "Android SDK Build-Tools .."
- "Android Emulator"
- "Android SDK Plattform-Tools"
- "Android SDK Tools"
If all installed then you can start the Emulator in Android Studio with "Tools" -> "Android" -> "AVD Manager". If the Emulator run you can try "react-native run-android"
回答6:
In my case, this was happening because the android/gradlew file did not have execute permission. Once granted, this worked fine
来源:https://stackoverflow.com/questions/38577669/run-react-native-on-android-emulator