Setup Flutter in Linux with Android Studio

Feri Lukmansyah
7 min readJun 6, 2021

--

Image from Unsplash

Hello And Welcome to other notes, in this post I will discuss how to set up flutter in Android Studio Linux.

here is a table of content

  • Install Android Studio
  • Install Flutter
  • Setup Flutter PATH
  • Problem With flutter doctor --android-licences
  • Switching Java OpenJDK to version 8
  • Install Android SDK using yay
  • Tips to Add Android SDK manually
  • Setup Android PATH
  • Setup Chrome PATH for Flutter web Support
  • Creating Emulators using sdkmanager
  • Can’t Create Flutter Project In Android Studio
  • Tips Using Android Studio for Flutter Project

History of Problem

I was Try Flutter Framework to developing Android Apps so I use Android Studio IDE, in my Linux Operating System (Arch Linux) I got many problems and mistakes, so I write this for documentation, happy reading

Install Android Studio

This first step is Installing android studio this is a have two method installations

Installing From JetBrains Toolbox

In this case, I will Install From JetBrains ToolBox, open Your Toolbox and Switch to Android Studio then click install

installing Android Studio From JetBrains ToolBox

Standalone Install

from Standalone Installing From Source download android studio from here

for ubuntu can read from official docs here list how to installing for Linux distro like ubuntu, etc

  • Ubuntu
  • Arch Linux
  • Manual From Aur (Another Arch Linux)

Installing With Yay

now let's look at how to install Android Studio for Arch Linux using yay

yay -S android-studio

Installing Manual From AUR

in addition to installing using yay, we install manually from AUR, lets go to the first step

go to android studio AUR repository clone the URL

git clone https://aur.archlinux.org/android-studio.git

then go to the directory and installed package dependencies

makepkg -si

input your password and wait until finished

if the app successfully installed SDK and other package dependencies have installed automatically if you open the IDE.

Installing Flutter

The next step is to install flutter refers to the official docs, I will install manually from the source in this case installing the stable version using git, and don’t forget to clone in /optdirectory

git clone https://github.com/flutter/flutter.git -b stable

Install The Plugin for Android Studio

install the plugins flutter on android studio

  1. Open plugin preferences (File > Settings > Plugins).
  2. Select Marketplace, select the Flutter plugin, and click Install.

Install The Plugin for Visual Studio Code

Install Plugins on Visual Studio Code

  1. Start VS Code.
  2. Invoke View > Command Palette….
  3. Type “install”, and select Extensions: Install Extensions.
  4. Type “flutter” in the extensions search field, select Flutter in the list and click Install. This also installs the required Dart plugin.

Installing Java-8-OpenJDK to fixing the problem with accept android licenses

why java version 8? because the flutter is requiring java-8-openjdk to accepting the licenses from the android SDK, so installing it from AUR or using yay

yay -S jdk8-openjdk

Problem with Multiple Java Version

if you already installed java but not the java version 8 you can switch using archlinux-java

sudo archlinux-java set "java-8-openjdk"

for example, you have multiple java version like this

java-15-openjdk (default)
java-8-openjdk

now you solved your problem

Setting /opt folder owner using chown

now if you add files or folder to /opt you need to change the owner of the folder so you no longer need sudoto extract packages or create folders

sudo chown pery:users /opt

pery is a users and users is a group

Setting Flutter Path

in the previous step, we clone in /opt directory now you can export the path like this

export PATH="$PATH:`pwd`/flutter/bin"

the problem is if you reboot your computer flutter will not be recognized by the system.

now the solution is, add an export command to .bashrc or .zshrc

# PATH FLUTTER
export PATH="$PATH:/opt/flutter/bin"

then restart your config using source refers to this answer

try to run flutter doctor command and you will see this result

[-] Android toolchain - develop for Android devices
• Android SDK at /Users/obiwan/Library/Android/sdk
✗ Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
• Try re-installing or updating your Android SDK,
visit https://flutter.dev/setup/#android-setup for detailed instructions.

Installing Manual SDK using yay

you can Install Manual SDK using yay, like this

yay -S android-sdk android-sdk-platform-tools android-sdk-build-tools android-platform

Tips Add Android SDK Manually (From Sources)

if you installing not using an android studio or you need to configure Android SDK PATH manually

why you need this?, if you install android studio in a small storage or your computer is full of memory, of course you can separate the android sdk in the PATH you want

now you need the required package to install Android SDK on your computer, the list has shown below in this case extract the downloaded package in /opt directory

Setting SDK PATH

now after the package installed in /opt directory setting path in your .bashrc or .zshrc

# Gradle PATH
export GRADLE_HOME=/opt/gradle-5.6.2
export PATH=$GRADLE_HOME/bin:$PATH
# Android Home
export ANDROID_HOME=/opt/android-sdk
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
# Android emulator PATH
export PATH=$ANDROID_HOME/emulator:$PATH
# Android SDK ROOT PATH
export ANDROID_SDK_ROOT=/opt/android-sdk
export PATH=$ANDROID_SDK_ROOT:$PATH

now run source command to apply changes

source .zshrc # change if you use .bashrc

Update Flutter Config SDK PATH

updating SDK config on flutter for custom SDK PATH

flutter config --android-sdk /opt/android-sdk

Setting Chrome PATH for Flutter Web Support

flutter web support needs a google-chrome browser path make sure installed in your computer or you can install using yay

yay -S google-chrome-stable

now to see chrome’s path use which command

which google-chrome
#/opt/google/chrome/google-chrome <- results

add to your .zshrc or .bashrc

# Chrome PATH
export PATH=$PATH:/opt/google/chrome

now run source command to apply changes

source .zshrc # change if you use .bashrc

Download pre-development binaries

flutter precache

accept android licenses with flutter

flutter doctor --android-licenses

if already accepted you see this result

Loading local repository...                                                  [=========                              ] 25% Loading local repository...    [=========                              ] 25% Fetch remote repository...     [==========                             ] 26% Fetch remote repository...     [============                           ] 32% Fetch remote repository...     [=============                          ] 34% Fetch remote repository...     [==============                         ] 36% Fetch remote repository...     [==============                         ] 38% Fetch remote repository...     [===============                        ] 39% Fetch remote repository...     [================                       ] 41% Fetch remote repository...     [=================                      ] 43% Fetch remote repository...     [=================                      ] 45% Fetch remote repository...     [==================                     ] 47% Fetch remote repository...     [===================                    ] 49% Fetch remote repository...     [====================                   ] 51% Fetch remote repository...     [====================                   ] 52% Fetch remote repository...     [=====================                  ] 54% Fetch remote repository...     [======================                 ] 56% Fetch remote repository...     [=======================                ] 58% Fetch remote repository...     [=======================                ] 60% Fetch remote repository...     [========================               ] 62% Fetch remote repository...     [=========================              ] 64% Fetch remote repository...     [==========================             ] 66% Fetch remote repository...     [==========================             ] 67% Fetch remote repository...     [===========================            ] 69% Fetch remote repository...     [============================           ] 71% Fetch remote repository...     [=============================          ] 73% Fetch remote repository...     [=============================          ] 75% Fetch remote repository...     [=============================          ] 75% Computing updates...           [=======================================] 100% Computing updates...          All SDK package licenses accepted.

running flutter doctor to check, now setup has complete

flutter doctor

you will see the result

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version
30.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] Connected device (1 available)
• No issues found!

Managing Emulators

managing your emulator carefully using command line

Update Emulator Binaries

you can create an emulator manually first update binaries

sdkmanager --sdk_root=${ANDROID_HOME} tools

Accept Emulator Licenses

accept licenses tools emulator using

sdkmanager --licenses

Creating Emulator with New Virtual devices

Create emulator with name pixel or choose the name you want

avdmanager -s create avd -n pixel -k "system-images;android-29;google_apis;x86_64"

Creating Emulator with Existing Devices

avdmanager -s create avd -n pixel -k "system-images;android-29;google_apis;x86_64" -d 19

Get List of Virtual Device

avdmanager list

Running the Flutter Emulator

flutter emulator --launch pixel

Problems After Setup Flutter that are often Encountered?

I often face problems after manual setup of Flutter and Android SDK, here are some of the problems

Can’t Create Flutter Project

it happens because the android APK support plugin is not enabled, therefore enable it in the plugins menu in the android studio

enable Android API support

then restart the Android Studio IDE

Problem Fixed 😄

that my little notes, that’s a small tip on how to setup Flutter on Linux and some mistakes that are often made when setting up Flutter and android studio on Linux, and some pragmatic setup tips, good luck and hopefully useful, thanks for reading

Useful Resources and References

--

--

Feri Lukmansyah
Feri Lukmansyah

Written by Feri Lukmansyah

A Software Engineer active on Upwork and Fiverr journal https://ferilukmansyah.dev

No responses yet