Search code examples
flutterandroid-studioadbdaemon

Cannot connect emulator in Android Studio on MacOS


I have a problem with the emulator that I cannot run my app on it. A few months ago, I still can open my old projects and run them on an emulator. After a few months, I come back with a new project and now I can open the emulator but it is not connected with my project (with my old projects too).

I see there are errors saying faild to start adb when I open my emulator and another notification says daemon is terminated. I google those to find solutions but nothing helps.

Here is my 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.

Due to my SSD only being around 125GB, I had to remove Xcode and all ios emulators a year ago so the Xcode section getting the error is fine. If I recall correctly when my app still runs fine on the emulator, I still see the error that says Flutter daemon terminated but it still runs fine so I don't think this could be an error. This error happens when I open android studio

Here is the error show whenever i start android emulator: Error when start emulator


Solution

  • I solved the problem of

    1. Cannot start emulator (emulator process is terminated)
    2. adb didn't ACK
    3. Flutter daemon is terminated

    Using these steps (Thanks to this post):

    1. Reinstall all Android Studio (After this, I still get the adb + daemon errors)
    2. Restart my Macbook to make sure no adb instance is running (After this I open Android Studio and see no daemon + adb errors but i get the new error when starting emulator called "Dyld Error Message")
    3. Close Android Studio
    4. Download and Unzip this older version emulator
    5. Open terminal and run open ~/Library/Android/sdk, this should open a folder, then replace the emulator folder with the one I just unzipped
    6. Run android studio normally

    OS: MacOS Mojave, IMO this error happens because newer emulator is not supporting old MacOS version. You can either UPGRADE your MacOS or DOWNGRADE emulator version