“Invalid Argument(s): Cannot find executable for null” when emulated Android on VS Code - Mac OS X

孤人 提交于 2020-05-24 03:31:06

问题


When I try to emulate Android on VS Code in Mac OS Catalina after installing Android SDK by Android Studio it returns the message: Invalid Argument(s): Cannot find executable for null. I have already created the environments variables ANDROID_SDK_ROOT and ANDROID_HOME both pointing for the same directory: /Users/anderson/Library/Android/sdk but I have no success.

flutter doctor diagnostic:

anderson@MacBook-Pro-de-Anderson ~ % flutter doctor Doctor summary (to see all details, run flutter doctor -v):

[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E266, locale en-BR)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)

[✓] Xcode - develop for iOS and macOS (Xcode 11.4)

[✓] Android Studio (version 3.6)

[✓] VS Code (version 1.43.2) [!] Connected device ! No devices available

! Doctor found issues in 1 category. anderson@MacBook-Pro-de-Anderson ~ %


回答1:


You can get this error both through command line flutter emulator --create flutteremu or using Flutter: Launch Emulator in Visual Studio Code.

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.

There is a log file, which details the error here.

If you dig deeper you fill find out that the following Android command line tool does not work:

avdmanager
No Java runtime present, requesting install.

Boo hoooooooo. So despite the fact that Android SDK is full of Java, you still need to install a separate Java just to run some command-line commands. Android SDK might not work if you have a wrong version of Java installed. Here is one good known version installed through Homebrew:

# Install Java 8 and Android SDK
brew tap homebrew/cask-versions

# See details here https://stackoverflow.com/a/61521063/315168
brew cask install adoptopenjdk/openjdk/adoptopenjdk8

Check that Java works now:

java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.252-b09, mixed mode)

Now in your shell make sure you have all correct environment variables.

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

And then run avdmanager again:

avdmanager list

And now you should be able to launch emulator with Flutter support:

flutter emulator --create flutteremu
No suitable Android AVD system images are available. You may need to install these using sdkmanager, for example:
  sdkmanager "system-images;android-27;google_apis_playstore;x86"

So let's install the images:

sdkmanager "system-images;android-27;google_apis_playstore;x86"

And now Flutter should be able to launch an emulator:

flutter emulator --create flutteremu

And finally it will work:

Emulator 'flutter_emulator' created successfully.

Close any running Visual Studio Code. Start Visual Studio Code from shell and explicitly set the environment variables for VSCode process:

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
code

And now Flutter: Launch Emulator works.



来源:https://stackoverflow.com/questions/61036745/invalid-arguments-cannot-find-executable-for-null-when-emulated-android-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!