【问题标题】:Unable to locate adb on macOS Catalina无法在 macOS Catalina 上找到 adb
【发布时间】:2020-12-03 15:07:53
【问题描述】:

我开始学习如何在 Android 环境中使用 ReactNative 进行移动编程。我正在使用 MacOS Catalina,并且已经安装了 android studio 和 react-native-cli。我跑了react-native init ShoppingList,它通过了

Downloading template, 
Copying template, 
Processing template 

但在Installing CocoaPods dependencies 失败,因为我还没有使用最新的操作系统(我希望这不是问题的一部分,因为我没有足够的内存来升级操作系统)

我提到了this issue 内部的一个建议,它要求我运行

npm uninstall -g react-native react-native-cli
npm install -g react-native react-native-cli
react-native start --reset-cache

我还删除了项目根目录下的 node_modules 和 npm install。然后在项目的根目录下运行react-native run-android

这给了我以下错误

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

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 '/Users/prashin/Test/ShoppingList/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

在 Android Studio 中,安装了以下内容

Android 11.0(R),
Android SDK Build-Tools, 
Android Emulator 30.2.6, 
Android SDK-Platform-Tools 30.0.5, 
Intel x86 Emulator Accelerator (HAXM installer) 7.5.1

我用Release name R(API Level 30创建了一个Pixel 2 Device),然后无数次按下播放按钮,它给了我AVD Manager: Unable to locate ADB的错误。

这是我的.bash_profile 文件。

source ~/.profile

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

##
# Your previous /Users/prashin/.bash_profile file was backed up as /Users/prashin/.bash_profile.macports-saved_2019-10-23_at_18:32:04
##

# MacPorts Installer addition on 2019-10-23_at_18:32:04: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export ANDROID_HOME=/Users/prashin/Library/Android/sdk
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH="$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"
# export PATH="$PATH:/Users/$USER/Library/Android/sdk/platform-tools"
# export PATH=${PATH}:/usr/local/mysql-5.7.31-macos10.14-x86_64/bin
# Finished adapting your PATH environment variable for use with MacPorts.

根据post,我确实在平台工具中看到了一个 adb 可执行文件。

我可能会在这里遗漏什么阻止我在模拟器上运行我的基本应用程序?如果需要更多信息,请通知我。

编辑

切换到.zprofile 的建议解决方案改为更改错误消息。在产生以下错误之前,它在info launching emulator 停留了 30 秒。

error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

> Task :app:stripDebugDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :app:installDebug FAILED
Skipping device 'emulator-5554' (emulator-5554): Device is OFFLINE.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
27 actionable tasks: 2 executed, 25 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No online devices found.

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

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

【问题讨论】:

    标签: macos react-native android-studio adb platform-tools


    【解决方案1】:

    对于 Catalina,Apple 已将默认 shell 更改为 zsh。因此,您必须重命名配置文件。 .bashrc 现在是 .zshrc.bash_profile 现在是 .zprofile。将 .bash_profile 的内容移动到新的 .zprofile 文件并重新启动终端。使用新的环境变量再次运行应用程序。

    【讨论】:

    • 虽然模拟器现在确实出现在playreact-native run-android 按钮上,但我仍然在play 按钮上收到“无法找到adb”的错误。对于该命令,错误已更改为“无法在 30 秒内启动模拟器”。我已将完整的错误消息粘贴到我原来的帖子中。
    • 您可以尝试运行 adb devices 并查看您的设备是否列在设备列表中吗?
    • 我尝试根据这篇帖子stackoverflow.com/questions/27970352/… 设置Catalina,但我只看到emulator-5544 unauthorized,这里的预期输出是什么?
    • 您可以尝试adb kill-server 并再次运行adb-devices 吗? Android 模拟器默认启用 USB 调试。如果一切正常,你就会得到这样的东西。 emulator-5544 device
    • 我仍然得到相同的输出。它总是说正在启动模拟器,然后 30 秒它说它处于离线状态
    【解决方案2】:

    只需重新启动终端就可以了...

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 2021-01-13
      相关资源
      最近更新 更多