Recently, I had the dubious privilege of getting to set up my developer machine from scratch. Don’t get me wrong; a new developer environment is a chance for a fresh start! New toys, new experiences, clean out the clutter! But, I am also a creature of habit and spend much fo the first month with a new machine stumbling over little gotchas and missteps regarding setup that I inevitably spend a half-hour googling only to wander upon a very familiar looking page of documentation, Stack Overflow post, or setup guide that details instruction I missed earlier. This is one such occasion.
After successfully configuring my new developer environment to dev for Xamarin.Forms, I turned my attention to setting up for Flutter development in preparation for some blog posts I was planning. After successfully testing my sample on iOS, I tried to run my app on an Android simulator only to realize there were none listed in my IDE! Running flutter doctor yielded some concerning callouts:
Doctor summary (to see all details, run flutter doctor -v): Unable to find any JVMs matching version "1.8". Unable to find any JVMs matching version "1.8". [✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-US) ⣽Unable to find any JVMs matching version "1.8". [!] Android toolchain - develop for Android devices (Android SDK version 29.0.2) ✗ Android license status unknown. Try re-installing or updating your Android SDK Manager. See https://developer.android.com/studio/#downloads or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions. [✓] Xcode - develop for iOS and macOS (Xcode 12.0) [!] Android Studio (not installed) [✓] VS Code (version 1.49.0) [✓] Connected device (2 available) ! Doctor found issues in 2 categories.
This was upsetting of course because 1) I wanted to test on Android, and 2) I had a simulator (which I was quite fond of) happily humming away that I had previously set up for testing in Xamarin which I had recently struggled to get working with my React Native install. Some careful googling pointed me in the right direction; as with React Native, Flutter was expecting my Android tools to be in the standard location provided by Android Studio. Since I started with Visual Studio first, I would need to update the default values to point to my non-standard-ish installation path that comes by default when installing via Visual Studio.
finding the right $path
As when I configured React Native, I needed to nab the SDK location from my Visual Studio instance to share with Flutter. In theory, this thought process follows if you install the Android SDK to a non-standard location via Android Studio or other IDE; simply locate the path from the preferences menu, like so:
The Preferences menu in Visual Studio for Mac
With that, we’ll need to run the following command to fix our Android SDK path in the eyes of Flutter:
flutter config --android-sdk /Users/jmeyer/Library/Developer/Xamarin/android-sdk-macosx Setting "android-sdk" value to "/Users/jmeyer/Library/Developer/Xamarin/android-sdk-macosx". You may need to restart any open editors for them to read new settings.
At this point, restarting the IDE showed an updated list of possible devices, including my android emulator that I was looking for:
An existing emulator and an option to create new devices appears after configuring flutter’s sdk path
That said, re-rerunning
flutter doctor still showed an error regarding licenses, as before. So! We still have references to fix, noting specifically the line:
Unable to find any JVMs matching version "1.8". Some cursory Googling revealed that my JVMs should be installed to
Library/Java/JavaVirtualMachines – taking a peek inside that directory, I found (in my case) I only had jdk 15 installed. After a few unsuccessful attempts to force Flutter to recognize that version, I relented and turned to homebrew to grab the legacy version, as suggested from this Stack Overflow post.
brew cask install homebrew/cask-versions/adoptopenjdk8
For good measure, I modified my .zprofile instance to explicitly set JAVA_HOME, like so:
export JAVA_HOME="`/usr/libexec/java_home -v 1.8`"
Now, restart any active terminal sessions and run the following command
flutter doctor --android-licenses
At this point, everything should be in place – we can restart the terminal and the IDE for good measure, then re-run flutter doctor to double check:
jmeyer@unknownf8ffc269ad8e ~ % flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 12.0) [!] Android Studio (not installed) [✓] VS Code (version 1.49.1) [✓] Connected device (2 available) ! Doctor found issues in 1 category.
Hooray! As you can see from the output, I haven’t gotten around to setting up Android Studio just yet, but at this point, I can do the majority of my Flutter work directly in Visual Studio Code and can grab Android Studio only when I actually need it. For now, I’m off and happily developing for Flutter in my new dev environment.