Flutter relies on a full installation of Android Studio to supply its Android platform dependencies. However, you can write your Flutter apps in a number of editors. this article discusses that.
Install Android Studio
- Download and install Android Studio.
- Start Android Studio, and go through the ‘Android Studio Setup Wizard’. This installs the latest Android SDK, Android SDK Command-line Tools, and Android SDK Build-Tools, which are required by Flutter when developing for Android.
flutter doctorto confirm that Flutter has located your installation of Android Studio. If Flutter cannot locate it, run
flutter config --android-studio-dir <directory>to set the directory that Android Studio is installed to.
Set up android device
There are two ways to run and test your Flutter app. One is on a real Android device, and the other is using an Android emulator.
Set up your real Android device
To prepare to run and test your Flutter app on an Android device, you need an Android device running Android 4.1 (API level 16) or higher.
- Enable Developer options and USB debugging on your device. Detailed instructions are available in the Android documentation.
- Windows-only: Install the Google USB Driver.
- Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
- In the terminal, run the
flutter devicescommand to verify that Flutter recognizes your connected Android device. By default, Flutter uses the version of the Android SDK where your
adbtool is based. If you want Flutter to use a different installation of the Android SDK, you must set the
ANDROID_SDK_ROOTenvironment variable to that installation directory.
Set up the Android emulator
If you prepare to run and test your Flutter app on the Android emulator, follow these steps:
Enable VM acceleration on your machine.
Launch Android Studio, click the AVD Manager icon, and select Create Virtual Device...
- In older versions of Android Studio, you should instead launch Android Studio > Tools > Android > AVD Manager and select Create Virtual Device…. (The Android submenu is only present when inside an Android project.)
- If you do not have a project open, you can choose Configure > AVD Manager and select Create Virtual Device…
Choose a device definition and select Next.
Select one or more system images for the Android versions you want to emulate, and select Next. An x86 or x86_64 image is recommended.
Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.
Verify the AVD configuration is correct, and select Finish.
For details on the above steps, see Managing AVDs.
In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.
Agree to Android Licenses
Before you can use Flutter, you must agree to the licenses of the Android SDK platform. This step should be done after you have installed the tools listed above.
Make sure that you have a version of Java 8 installed and that your
JAVA_HOMEenvironment variable is set to the JDK’s folder.
Android Studio versions 2.2 and higher come with a JDK, so this should already be done.
Open an elevated console window and run the following command to begin signing licenses.
flutter doctor --android-licenses
Review the terms of each license carefully before agreeing to them.
Once you are done agreeing with licenses, run
flutter doctoragain to confirm that you are ready to use Flutter.