Skip to main content

Setup Flutter with Android Command Line Tools

·3 mins

Install Java Development Kit (or OpenJDK) #

For Android 13 (API level 33), its required to install JDK version 17.

Install on Windows with the Windows Package Manager (winget)

Search for the latest version with winget search Microsoft.OpenJDK command and then install the lastest version like following.

$ winget install Microsoft.OpenJDK.17

Install on Ubuntu Linux with apt package manager

$ sudo apt install openjdk-17-jdk

Install on macOS with HomeBrew and follow the on-screen instructions

$ brew install openjdk@17

Now for macOS only, symbolic link installed java to system folder.

$ sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Install Git #

Install on Ubuntu Linux

$ sudo apt install git

Install on macOS

$ brew install git

Install on Windows

$ winget install -e --id Git.Git

Install Flutter SDK Tools #

Download Flutter desired OS from the following URL.

https://docs.flutter.dev/get-started/install

Now extract the zip and put the flutter folder to home directory, so the final directory for flutter will be <HOME_PATH>/flutter.

Install Android Command Line Tools #

In the home directory we will create a folder called “android”.

Download Android command-line tools for desired OS from the following URL.

https://developer.android.com/studio#command-line-tools-only

Now extract and move the unziped folder to the <HOME_PATH>/android/cmdline-tools/ directory and rename it to latest. So the command line tools will reside in <HOME_PATH>/android/cmdline-tools/latest.

Set Some Environment Variables #

In Windows

From the start search bar, enter env and select Edit environment variables for your account. Under User variables add or edit following variables.

“…” in Path is the existing paths if any already setup.

ANDROID_HOME="%USERPROFILE%/android"
Path="...;%USERPROFILE%\flutter\bin;%ANDROID_HOME%/cmdline-tools/latest/bin;%ANDROID_HOME%/platform-tools"

In Ubuntu Linux

Open up the .bashrc file for setting up some environment variables.

$ cd ~
$ nano .bashrc 

Write this at the end of the .bashrc file.

# Android
export ANDROID_HOME="$HOME/android"
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"
export PATH=$ANDROID_HOME/platform-tools:$PATH
# Flutter
export PATH="$HOME/flutter/bin:$PATH"

In macOS

Open up the .zshrc file for setting up some environment variables.

# Flutter
export PATH="$HOME/flutter/bin:$PATH"
# Java
JAVA_HOME=$(/usr/libexec/java_home)
export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"
# Android
ANDROID_HOME="$HOME/android"
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"

Download Android SDK #

I am downloading android-33 SDK, so will use following commands.

$ sdkmanager "system-images;android-33;default;arm64-v8a"
$ sdkmanager "build-tools;33.0.0"
$ sdkmanager "platforms;android-33"
$ sdkmanager "platform-tools"

To get the list of available SDK versions following command can be used.

$ sdkmanager --list

Configure SDK path for Flutter #

$ flutter config --android-sdk ~/android

Call To Flutter Doctor #

$ flutter doctor -v

If it ask for Accept Licenses with flutter doctor use below command to accept licenses

$ flutter doctor --android-licenses

Create Emulator (AVD) #

$ avdmanager create avd -n "Pixel_7" -k "system-images;android-33;default;arm64-v8a" -d pixel_7

What’s Next #

Now you can create a flutter project and run it.

cd Documents/
flutter create hello_world
cd hello_world
flutter run