无法在 MacOS 上的 Android Studio 中连接模拟器

Cannot connect emulator in Android Studio on MacOS

我的模拟器有问题,我无法 运行 我的应用程序。几个月前,我仍然可以在模拟器上打开我的旧项目并 运行 它们。几个月后,我带着一个新项目回来了,现在我可以打开模拟器,但它没有连接到我的项目(也包括我的旧项目)。

当我打开我的模拟器时,我看到有错误说 faild to start adb,并且另一个通知说 daemon is terminated。我 google 那些寻找解决方案但没有任何帮助。

这是我的flutter doctor -v

or found issues in 3 categories.
Macbooks-MacBook-Pro-3:learning_bee quanan$ flutter doctor -v
[✓] Flutter (Channel dev, 2.3.0-24.0.pre, on Mac OS X 10.14.6 18G2022 darwin-x64, locale en-US)
    • Flutter version 2.3.0-24.0.pre at /Users/quanan/Downloads/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2b9537c783 (5 months ago), 2021-06-11 22:11:53 -0700
    • Engine revision ddbac024d1
    • Dart version 2.14.0 (build 2.14.0-188.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/quanan/Library/Android/sdk
    • Platform android-30, build-tools 31.0.0
    • Java binary at: /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] VS Code (version 1.62.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[☠] Connected device (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
      https://github.com/flutter/flutter/issues.
    ✗ Exception: Unable to run "adb", check your Android SDK installation and ANDROID_SDK_ROOT environment variable:
      /Users/quanan/Library/Android/sdk/platform-tools/adb
    • #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
      #1      AndroidDevices.pollingGetDevices (package:flutter_tools/src/android/android_device_discovery.dart:78:7)
      <asynchronous suspension>
      #2      PollingDeviceDiscovery._populateDevices (package:flutter_tools/src/device.dart:397:54)
      <asynchronous suspension>
      #3      Future.wait.<anonymous closure> (dart:async/future.dart)
      <asynchronous suspension>
      #4      DeviceManager.getAllConnectedDevices (package:flutter_tools/src/device.dart:163:40)
      <asynchronous suspension>
      #5      DeviceValidator.validate (package:flutter_tools/src/doctor.dart:515:34)
      <asynchronous suspension>
      #6      asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:24)
      <asynchronous suspension>


! Doctor found issues in 3 categories.

由于我的 SSD 只有 125GB 左右,我不得不在一年前删除 Xcode 和所有 ios 模拟器,所以 Xcode 部分得到错误是好的。 如果我没记错的话,当我的应用程序在模拟器上仍然 运行 正常时,我仍然会看到显示 Flutter daemon terminated 的错误,但它仍然 运行 正常,所以我不认为这可能是一个错误。当我打开 android studio

时发生此错误

这是我启动 android 模拟器时显示的错误:

我解决了

的问题
  1. 无法启动模拟器(模拟器进程已终止)
  2. adb 没有确认
  3. Flutter 守护进程已终止

使用这些步骤(感谢 this post):

  1. 重新安装所有 Android Studio(在此之后,我仍然遇到 adb + daemon 错误)
  2. 重新启动我的 Macbook 以确保没有 adb 实例 运行ning(在此之后我打开 Android Studio 并且没有看到守护进程 + adb 错误但是我在启动名为“的模拟器时收到新错误Dyld 错误消息")
  3. 关闭Android工作室
  4. 下载并解压缩 older version emulator
  5. 打开终端和运行 open ~/Library/Android/sdk,这应该会打开一个文件夹,然后将模拟器文件夹替换为我刚刚解压的文件夹
  6. 运行 android 正常工作室

OS: MacOS Mojave, IMO 发生此错误是因为较新的模拟器不支持旧的 MacOS 版本。您可以 UPGRADE 您的 MacOS 或 DOWNGRADE 模拟器版本