[英]Getting error while running React Native app: Failed to install the app. Make sure you have the Android development environment set up
[英]React-Native: error Failed to install the app. Make sure you have an Android emulator running
我剛剛通過以下方式初始化了一個新的 React Native 項目:
react-native init AwesomeProject
我已經收到此錯誤:
BUILD FAILED in 3s
error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
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 3s
at checkExecSyncError (child_process.js:637:11)
at execFileSync (child_process.js:655:13)
at runOnAllDevices (/Users/danale/Projects/engageMobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:75:39)
at buildAndRun (/Users/danale/Projects/engageMobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:169:41)
at then.result (/Users/danale/Projects/engageMobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:135:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
到目前為止,它只是一個樣板應用程序。 我使用 zsh 而不是 bash 作為命令行界面。
我也在顫振中開發,我沒有遇到這個問題,它可以順利打開 Nexus 5X 模擬器。
可能是什么問題呢?
我嘗試更改權限,但事實並非如此。
所以顯然我比android
有更多的ios
經驗,而react-native run-ios
自動為你打開一個模擬器, react-native run-android
沒有,重要的一點,類似的命令,不要做類似的事情,即打開起一個模擬器。
一旦我在 Android Studio 中打開應用程序,然后轉到AVD Manager並打開 Android Studio 的模擬器,然后運行react-native run-android
,它就完美運行了。
如果你的 nodejs 已經在運行或者在 init 項目之前已經連接了任何設備,那么它不會被考慮用於 react-native。
確保您的 Android 模擬器正在運行。 關閉所有終端窗口。 運行 'react-native run-android' 它應該會打開兩個終端窗口。 如果您再次看到相同的錯誤,請關閉第二個終端(編譯的那個),然后在 1 個打開的終端中運行“npm start”。
我遇到了同樣的問題。 即使我的 android 模擬器工作正常,偶爾也會發生一些損壞,然后 react-native run-android 拋出上述錯誤。
一種對我有用的解決方案是關閉所有命令提示符,關閉虛擬設備並重新運行它們,這對我來說總是有效的。
基本上在android studio中打開你的react native項目,它會在android studio而不是命令終端下載gradle。 然后打開你的命令終端並運行代碼“npm run android”,它應該可以工作
我想你忘了先創建虛擬設備。
完成后,您可以在 cmd/terminal npx react-native run-android
上運行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.