簡體   English   中英

npx react-native run-android 不啟動模擬器,如果模擬器正在運行則不運行

[英]npx react-native run-android doesn't start emulator and doesn't run if emulator is running

我使用 react-native 0.63 創建了一個新項目,當我在 ios 模擬器上運行時一切正常,但是當嘗試在 android 上運行時,它不起作用並給我這個錯誤

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Volumes/SSD2/developer/MyProject/AwesomeProject/android/local.properties'.

* 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 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

我安裝 react-native 就像react-native 設置

這是我的 react-native 醫生給我的 output

✓ Node.js
 ✓ npm
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 29.0.2
 ✖ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI

Errors:   2
Warnings: 0

如果我運行 npx react-native start 然后應用程序從 android 工作室順利運行。

如果我從終端 source.bash_profile 運行項目,請編輯

模擬器啟動但項目未運行

"--no-jetifier" flag.
Jetifier found 5194 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
env: sh\r: No such file or directory

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
env: sh\r: No such file or directory

看起來您需要設置 ANDROID_HOME 環境變量。

將以下行添加到您的 $HOME/.bash_profile 或 $HOME/.bashrc(如果您使用的是 zsh,則使用 ~/.zprofile 或 ~/.zshrc)配置文件:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

為 bash 鍵入 source $HOME/.bash_profile 或 source $HOME/.zprofile 將配置加載到您當前的 shell 中。 通過運行 echo $ANDROID_HOME 驗證 ANDROID_HOME 是否已設置,並且通過運行 echo $PATH 已將適當的目錄添加到您的路徑中。

請確保使用正確的 Android SDK 路徑。 You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under Appearance & Behavior → System Settings → Android SDK.

參考:

配置 ANDROID_HOME 環境變量

React Native 工具需要設置一些環境變量才能使用本機代碼構建應用程序。

Go 到主目錄並顯示隱藏文件,然后將以下行添加到您的~/.zprofile~/.zshrc /.zshrc (如果您使用的是 bash 終端,則添加~/.bash_profile~/.bashrc )配置文件:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

在根終端中運行source ~/.zprofilesource ~/.zshrc /.zshrc(或source ~/.bash_profilesource ~/.bashrc for bash)以將配置加載到當前的 shell。通過運行 echo 驗證是否已設置 ANDROID_HOME $ANDROID_HOME 和相應的目錄已通過運行 echo $PATH 添加到您的路徑中。

如果錯誤仍然存在,請重新啟動系統。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM