Install Flutter on Arch Linux

flutter gutter

Warning
This article was last updated on 2022-04-12, the content may be out of date.

Getting Flutter and Android working together is no small feat.

Linux may be a first-class citizen when it comes to developing with Flutter, but setting up Java, Android and the Android tool-chain can be a real hassle.

This blog post shows how get Flutter working with Android SDK without installing Android Studio.

Android Studio is a fully-fledged IDE. If you want to use a different development editor (like Vim or VS Code), Android Studio is only good for eating space on your hard drive.

Arch Linux comes with the fabulous Arch package manager and the AUR, the Arch User Repository. The AUR offers dozens of useful packages which we can use to set up Android SDK.

Caution
Please be aware that you need around 7 GB of free disk space for Flutter and Android SDK.

Use the AUR for installing Flutter:


1
yay -S flutter

(yay enables you to install AUR packages.)

Choose Openjdk 8 or 10. Otherwise you’ll get an error with the Android tools: Failed to install android-sdk: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema.

Create a new group flutterusers, add the default user to the group, then change permissions on the folder /opt/flutter.

The group may have been created beforehand so you may not need to do this. It’s no harm in doing it again anyway.


1
2
3
4
sudo groupadd flutterusers
sudo gpasswd -a $USER flutterusers
sudo chown -R :flutterusers /opt/flutter
sudo chmod -R g+w /opt/flutter/

If you still get permission denied errors, you can also change the permissions of the /opt/flutter folder to your $USER:


1
sudo chown -R $USER:flutterusers /opt/flutter

While we can avoid installing the heavy Android Studio program, we still need the SDK Manager.

You can install the SDK Manager command line tool as a standalone package. We also need the platform tools for the Android emulator and an SDK platform.


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

The AUR installs the Android tools into /opt/android-sdk. The directory has root permissions, so we’ll need to fix that:


1
2
3
4
sudo groupadd android-sdk
sudo gpasswd -a <user> android-sdk
sudo setfacl -R -m g:android-sdk:rwx /opt/android-sdk
sudo setfacl -d -m g:android-sdk:rwX /opt/android-sdk

You’ll probably also have to set up environment variables for ANDROID_SDK_ROOT and JAVA_HOME.

The Java version is under /usr/lib/jvm, in the case of version 8, it’s this:


1
export JAVA_HOME='/usr/lib/jvm/java-8-openjdk'

Tip

If you have other version of openjdk installed, you may have to change the default Java environments.

First, try checking your default environment by using:

1
archlinux-java status

The output will look like this:

1
2
3
Available Java environments:
  java-15-openjdk
  java-8-openjdk (default)

If it’s not the case, then changing the environment:

1
sudo archlinux-java set java-8-openjdk

First, you’ll need to install the required Android image with sdkmanager:


1
sdkmanager --list

Then install a system image, for example:


1
sdkmanager --install "system-images;android-30;default;x86"

Now you can create an emulator:


1
avdmanager create avd -n <name> -k "system-images;android-29;default;x86"

(Replace <name> with the name you want to give the emulator.)


Put these lines in your .bashrc/.zshrc:


1
2
3
4
5
export ANDROID_SDK_ROOT='/opt/android-sdk'
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools/
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin/
export PATH=$PATH:$ANDROID_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/

Tip
It seems like sdkmanager adds some paths automatically. Make sure to check your installation to see what’s required.
Caution

If you encounter the error: “PANIC: Missing emulator engine program for ‘x86’ CPUS.”. It indicates that the emulator program is not in your path. Adding this line in .bashrc/.zshrc works for me:

1
alias emulator='$ANDROID_SDK_ROOT/emulator/emulator'
1
emulator @<name-of-the-generated-avd>

## Verifying Flutter

Check if you have accepted all licenses:

flutter doctor --android-licenses.

Then run flutter doctor.

The output will look like this:


1
2
3
4
5
6
7
8
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 2.2.0, on Linux, locale en_US.UFT-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!

flutter.png
Flutter is successfully installed


Everything should work now except for Android Studio (unless you installed one).

Installing the Android toolchain without Android Studio can be very tricky if you don’t add the correct paths to your shell environment.

It’s also not easy to find out what you have to install and how to do it.

The above worked for me after spending a few hours. Time I’ll never get back.

Hopefully, this guide will help someone else (and if it’s only my future self).