Repository: flutter
Issue: flutter doctor: detect broken avdmanager: Cannot find executable for null
Labels: c: crash,platform-android,tool,t: flutter doctor,P2,team-android,triaged-android

You can get this error both through command line `flutter emulator --create flutteremu` or using *Flutter: Launch Emulator* in Visual Studio Code on macOS.

After installing Android SDK and Flutter SDK, the Flutter emulator run does not work.

```
Oops; flutter has exited unexpectedly: "Invalid argument(s): Cannot find executable for null.".
```

You get this error despite `flutter doctor` telling you that everything is in order.

If you dig deeper you fill find out that the following Android command-line tool does not work:

```sh
avdmanager
```

```
No Java runtime present, requesting install.
```

Turns out that `avdmanager` is quite a tricky to get running on macOS, as it seems to fall short on the default Android SDK installation.  You need to have an external `java` installed and then you need to make sure all environment variables are wired correctly. Plus pinning down a correct Java version was not that easy. The suggested Oracle JDK by the macOS itself did not do the trick.

[I wrote a detailed instructions how to get this fixed on this StackOverflow answer](https://stackoverflow.com/questions/61036745/invalid-arguments-cannot-find-executable-for-null-when-emulated-android-on/61869002#61869002).

The correct bug fix would be that `flutter doctor` detects the condition when the user cannot run `avdmanager` and tells the user that this needs to be fixed.

A log from `flutter emulator --create flutteremu` is:

```
Flutter crash report; please file at https://github.com/flutter/flutter/issues.

## command

flutter emulator --create flutteremu

## exception

ArgumentError: Invalid argument(s): Cannot find executable for null.

#0      _getExecutable (package:process/src/interface/local_process_manager.dart:127:5)
#1      LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:94:30)
#2      _DefaultProcessUtils.runSync (package:flutter_tools/src/base/process.dart:417:51)
#3      EmulatorManager._getPreferredAvailableDevice (package:flutter_tools/src/emulator.dart:144:46)
#4      EmulatorManager.createEmulator (package:flutter_tools/src/emulator.dart:82:33)
<asynchronous suspension>
#5      EmulatorsCommand._createEmulator (package:flutter_tools/src/commands/emulators.dart:78:31)
#6      EmulatorsCommand.runCommand (package:flutter_tools/src/commands/emulators.dart:48:13)
#7      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:722:18)
#8      _rootRunUnary (dart:async/zone.dart:1192:38)
#9      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#10     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#11     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#12     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#13     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#14     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#15     _rootRun (dart:async/zone.dart:1184:13)
#16     _CustomZone.run (dart:async/zone.dart:1077:19)
#17     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#18     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#19     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#20     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#21     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#22     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
```

## flutter doctor

```
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-GI)
    • Flutter version 1.17.0 at /Users/moo/code/flutter
    • Framework revision e6b34c2b5c (2 weeks ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/moo/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • ANDROID_SDK_ROOT = /Users/moo/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    ✗ CocoaPods not installed.
        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 install:
        sudo gem install cocoapods

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.8052
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.45.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.2

[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.
```