flutter without Android Studio
Here are my unorganized notes from my struggles with setting up Flutter on Windows. Because it has all you need build into it's console tools - even a debugger run as a local web application - you don't really need an IDE (especially the heavy and slow Android Studio).
As it turned out it was not so easy to configure everything without it - but it can be done. So this post is for everyone who prefer to work with just text editor and a terminal.
But beware - this is specific for Windows and is quite crude. It's not a tutorial - rather a bunch of notes from my process. It should still be helpful tho for some of you.
Installation and configuration
I downloaded flutter_windows_v1.7.8+hotfix.4-stable.zip
from website:
flutter.dev/docs/get-started/install/windows
Unpacked to C:\flutter
and added to PATH
.
Output from running flutter doctor
PS> flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.7.8+hotfix.4, on Microsoft Windows [Version 10.0.17763.615], locale pl-PL) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.1) [!] Android Studio (version 3.3) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. [!] IntelliJ IDEA Community Edition (version 2019.2) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. [!] VS Code (version 1.36.1) X Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [!] Connected device ! No devices available ! Doctor found issues in 4 categories.
I have Android toolchain because it was installed with the Android Studio. It's and older installation tho so the Android SKD is probably older too.
I'm not gonna use the Android Studio, same goes for detected IntelliJ and VS Code. All those tool are on my system just temporary for a different project.
It's worth so fix the devices issue tho. I do not want to use my phone for development (it's old and slow). In the old Android Studio I have there are some virtual machines but also old and slow ones. The new Android Studio emulator is faster so it might be worth to install new Android Studio just to get the faster virtual machine.
I will see if there are some mentions about that in the flutter's docs.
Android SDK and Emulation
I removed my Android Studio from my system and I will try to use just the flutter and Android SDK.
I found those in: ~\AppData\Local\Android\Sdk\
Also in
directory tools\bin
are some tools to manage SDK and virtual
machines. I will try to use that to configure one and use it for flutter.
Here are the docs for those CLI tools: developer.android.com/studio/command-line
Command .\avdmanager.bat list avd
prints out empty list -
probably 'cause I don't have any VMs yet. I can add a new one using:
.\avdmanager.bat create avd
. The entire command:
PS> .\avdmanager.bat create avd -n FlutterTest -k "system-images;android-29;google_apis;x86" PS> .\avdmanager.bat list avd Available Android Virtual Devices: Name: FlutterTest Path: ~\.android\avd\FlutterTest.avd Target: Google APIs (Google Inc.) Based on: Android API 29 Tag/ABI: google_apis/x86
To run the created VM you have to use the emulator.exe
from the
emulator>
directory. More details here:
developer.android.com/studio/run/emulator-commandline.html
Exact command:
PS> .\emulator.exe -avd FlutterTest HAX is working and emulator runs in fast virt mode. Your emulator is out of date, please update by launching Android Studio: - Start Android Studio - Select menu "Tools > Android > SDK Manager" - Click "SDK Tools" tab - Check "Android Emulator" checkbox - Click "OK"
After VM start a message was shown that my graphic's card drivers might not be stable so the device is run in compatibility mode.
The emulator command out is not ideal either. I will try to update the emulator but firstly I will test if it works at all. Looks like it does but the performance is terrible. Also the resolution is quite small.
I have found some settings in file:
~\.android\avd\FlutterTest.avd\hardware-qemu.ini
related to screen dimensions but after making changes to the file those were
reverted back to the previous values after running the emulator again.
So I've tried to update the SKD using sdkmanager.bat
from
tools\bin
:
PS> .\sdkmanager.bat --list | sls emulator Warning: File ~\.android\repositories.cfg could not be loaded. emulator | 29.0.11 | Android Emulator extras;intel;Hardware_Accelerated_Execution_Manager | 7.5.2 | Intel x86 Emulator Accelerator (HAXM installer) emulator | 29.0.11 | Android Emulator extras;google;auto | 1.1 | Android Auto Desktop Head Unit emulator extras;intel;Hardware_Accelerated_Execution_Manager | 7.5.2 | Intel x86 Emulator Accelerator (HAXM installer)
(I have slightly modified the output to make it more narrow.)
I've run .\sdkmanager.bat --update
and it made it worse:
WARNING: unexpected system image feature string, emulator might not function correctly, please try updating the emulator. Unexpected feature list: MultiDisplay VulkanNullOptionalStrings YUV420888toNV21 YUVCache HAX is working and emulator runs in fast virt mode. Your emulator is out of date, please update by launching Android Studio: - Start Android Studio - Select menu "Tools > Android > SDK Manager" - Click "SDK Tools" tab - Check "Android Emulator" checkbox - Click "OK"
Emulator still claims that it is old but it also shows new error.
On the very bottom of: developer.android.com/studio is
section Command line tools only
in which I've found:
sdk-tools-windows-4333796.zip
. One cannot select version there.
I've just unpacked it into a AndroidSDK
folder in my home directory.
But in order to make flutter work with that I had to create environment
variable ANDROID_HOME
which I new from the flutter output:
PS> flutter doctor [X] Android toolchain - develop for Android devices X Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.dev/setup/#android-setup for detailed instructions). If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location. You may also want to add it to your PATH environment variable.
After doing that and rerunning the command I've got:
PS> flutter doctor [!] Android toolchain - develop for Android devices ! Android SDK contains licenses only. Your first build of an Android application will take longer than usual, while gradle downloads the missing components. This functionality will only work if the licenses in the licenses folder in ANDROID_HOME are valid. If the Android SDK has been installed to another location, set ANDROID_HOME to that location. You may also want to add it to your PATH environment variable.
Let's see if that will work.
Running sdkmanager
:
PS> .\sdkmanager.bat Warning: File ~\.android\repositories.cfg could not be loaded. [=======================================] 100% Computing updates...
I've just created empty file and warning went away.
So it turns out with the use of .\sdkmanager.bat --install
You can not only install but also update packages:
.\sdkmanager.bat --install emulator .\sdkmanager.bat --install "build-tools;29.0.2" .\sdkmanager.bat --install "system-images;android-29;google_apis;x86" .\sdkmanager.bat --install tools
The installation went without any issues and warnings. Let's test the emulator. So I will create new VM again and run it.
PS> .\avdmanager.bat create avd -n FlutterTest -k "system-images;android-29;google_apis;x86" --force PS> .\emulator.exe -avd FlutterTest PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
An other environment variable to add. But it didn't help. No matter where
I would point it the panic would not go away. From the post:
stackoverflow.com/a/44386974/2102807
I deduced that I have not installed all required dependencies. I removed the
ANDROID_SDK_ROOT
variable and installed additional tools:
.\sdkmanager.bat --install platform-tools .\sdkmanager.bat --install "platforms;android-29"
It allowed emulator to run but the warnings stayed the same:
PS> .\emulator.exe -avd FlutterTest WARNING: unexpected system image feature string, emulator might not function correctly, please try updating the emulator. Unexpected feature list: MultiDisplay VulkanNullOptionalStrings YUV420888toNV21 YUVCache HAX is working and emulator runs in fast virt mode.
And it would still switch into compatibility mode:
--------------------------- GPU Driver Issue --------------------------- Your GPU driver information: GPU #1 Make: 8086 Model: Intel(R) HD Graphics Family Device ID: 0a16 Some users have experienced emulator stability issues with this driver version. As a result, we're selecting a compatibility renderer. Please check with your manufacturer to see if there is an updated driver available. --------------------------- OK ---------------------------
So I've read on the internet that this warning might be related to the newest Android 29. I will try older version - 28. The executed commands:
cd tools/bin .\sdkmanager.bat --install "build-tools;28.0.3" .\sdkmanager.bat --install "system-images;android-28;google_apis;x86_64" .\sdkmanager.bat --install "platforms;android-28" .\avdmanager.bat create avd -n Flutter28 -k "system-images;android-28;google_apis;x86_64" cd ../../emulator .\emulator.exe -avd Flutter28
AND THAT WORKED! No more warnings.
WARNING: unexpected system image feature string, emulator might not function correctly, please try updating the emulator. Unexpected feature list: MultiDisplay VulkanNullOptionalStrings YUV420888toNV21 YUVCache
Except this one regarding the driver. But the VM seems to work quite faster now. I will then remove the Android 29 tools and work with 28 version:
cd tools/bin .\sdkmanager.bat --uninstall "build-tools;29.0.2" .\sdkmanager.bat --uninstall "system-images;android-29;google_apis;x86_64" .\sdkmanager.bat --uninstall "platforms;android-29"
I've found Intel® Driver & Support Assistant (Intel® DSA).
It seems to be and automatic Intel tool for detecting and installing required
drivers. Unfortunately the tools said that all is in order and installed
nothing.
I've tried to run the emulator in different modes -gpu
following the documentation:
developer.android.com/studio/run/emulator-acceleration
but without any effect.
But I've noticed that the emulation works quite well now. I have no idea what I've changed. But is still has very low resolution.
OK I know what I have changed. After starting the VM go:
Settings > Advanced (tab at the top)
and change the section OpenGL ES renderer
to Desktop
native OpenGL.
After some investigation I determined that this setting is being saved into:
snapshots\default_boot\snapshot.pb
file and that is a binary file.
The conclusion is that You cannot setup this before the first run of the VM. You have to suffer through the first slow run and change this setting and restart.
Regarding the resolution. I have found out that the configuration file is
the config.ini
and that is the only file you can change as the
hardware*.ini
files are being overrided after each run. So enter:
hw.lcd.width = 480 hw.lcd.height = 800 hw.lcd.density = 320
And it works. But you have to know that there are strict limits as to which values are allowed:
QVGA (240x320, low density, small screen) WQVGA400 (240x400, low density, normal screen) WQVGA432 (240x432, low density, normal screen) HVGA (320x480, medium density, normal screen) WVGA800 (480x800, high density, normal screen) WVGA854 (480x854 high density, normal screen) WXGA720 (1280x720, extra-high density, normal screen) WSVGA (1024x600, medium density, large screen) WXGA800-7in (1280x800, high density, large screen) new WXGA800 (1280x800, medium density, xlarge screen) available lcd densities are: 120, 160, 213, 240, 280, 320, 360, 400, 420, 480, 560, 640
After achieving that I'm not sure that I actually need such big screen. So I went back to the previous settings:
hw.lcd.width = 320 hw.lcd.height = 480 hw.lcd.density = 120
You start the emulator with a command:
.\emulator.exe -avd Flutter28
Flutter sees the emulator:
PS> flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.7.8+hotfix.4, on Microsoft Windows [Version 10.0.17763.615], locale pl-PL) [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [!] Android Studio (not installed) [!] VS Code (version 1.36.1) X Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [√] Connected device (1 available)
After some time it turned out that I needed more space on the emulator so I've changed that in the configuration file:
disk.systemPartition.size = 2562m disk.vendorPartition.size = 1000m disk.dataPartition.size = 1000m
Building and running the project
I followed the instruction: flutter.dev/docs/get-started/test-drive?tab=terminal
I've generated new project with flutter create flutter1
.
You cannot have upper case letters in the project name.
PS> flutter devices 1 connected device: Android SDK built for x86 64 • emulator-5554 • android-x64 • Android 9 (API 28) (emulator)
Flutter sees the device so I executed flutter run
Flutter warned me that the first run might take a while and indeed it took
a couple of minutes:
PS> flutter run Using hardware rendering with device Android SDK built for x86 64. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering". Launching lib/main.dart on Android SDK built for x86 64 in debug mode... Initializing gradle... (This is taking an unexpectedly long time.) \
The summary said that it took: 214 s - 3 min
and I had to accept firewall rule.
214,7s (!) Resolving dependencies... 66,7s
During entire process my machine was screaming with fans. At the end I've got and error:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. > Could not find tools.jar. Please check that C:\Program > Files\Java\jre1.8.0_221 contains a valid JDK installation. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 40s Running Gradle task 'assembleDebug'... Running Gradle task 'assembleDebug'... Done 41,9s Gradle task assembleDebug failed with exit code 1
The important fragment:
Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_221 contains a valid JDK installation.
stackoverflow.com/a/56498542/2102807:
This can occur if your path is too long as well. I solved this by moving my java install to C:\Java\jdk1.8.0_211
I hope that this is not the issue as my path is not that long - but it has spaces so that might be the issue.
In gradle.properties
file you can specify the java path:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_121
And that helped. The build process finished and application run. Also Hot reloading works.
Debug/Release/Profile & Headless Test?
By default application is build and run in debug mode. Flutter has three modes: debug, release and profile. More about those here:
In debug mode you can use assert()
flutter run # debug flutter run --release # release flutter run --profile # profile
There is also one mode for tests without visible interface.
The command for this one is: flutter test
.
DevTools
flutter.dev/docs/development/tools/devtools/overview
PS> flutter pub global activate devtools ... Warning: Pub installs executables into C:\flutter\.pub-cache\bin, which is not on your path. You can fix that by adding that directory to your system's "Path" environment variable. A web search for "configure windows path" will show you how. ...
Running:
flutter pub global run devtools