< Back to | Open article on dev.to

Configure Flutter development environment on Manjaro/Arch linux.

Linux is an amazing OS for Flutter development, but setting up Java, Android and the Android tool-chain can be a really difficult.In this blog post I'll show you how to get Flutter working with Android SDK without installing Android Studio.
I'll be using Neovim for writing code , you can use vscode or any other text editor.

Let's start setting up Flutter development environment

Installing Yay package manager

We are going to install almost all of packages from Arch User Repository. For that you need to install yay package manager
Open your terminal and run this command.

      pacman -S --needed git base-devel
      git clone https://aur.archlinux.org/yay.git
      cd yay
      makepkg -si
Enter fullscreen mode Exit fullscreen mode

Installing Flutter

yay -S flutter
Enter fullscreen mode Exit fullscreen mode

Make sure that you have openjdk 8 or 10 by this command

java -version

if java version is other than 8 or 10 then install openjdk 8 using

sudo pacman -S jre8-openjdk

And put this line in your .bashrc or .zshrc

export JAVA_HOME='/usr/lib/jvm/java-8-openjdk'
export PATH=$JAVA_HOME/bin:$PATH 
Enter fullscreen mode Exit fullscreen mode

Set permissions

Yay installs Flutters in /opt/flutter directory.Which can only be accessed by Root user, so we need to set appropriate permissions. Run these commands in your terminal.

  sudo groupadd flutterusers
  sudo gpasswd -a $USER flutterusers
  sudo chown -R :flutterusers /opt/flutter
  sudo chmod -R g+w /opt/flutter/
Enter fullscreen mode Exit fullscreen mode

if you get some weird permission denied errors try this

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

Android SDK and tools

To install Android SDK and other required tools run these commands in your terminal

yay -S android-sdk android-sdk-platform-tools android-sdk-build-tools
yay -S android-platform
Enter fullscreen mode Exit fullscreen mode

User permissions

android-sdk is installed in /opt/android-sdk directory, So need to set appropriate permissions

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
Enter fullscreen mode Exit fullscreen mode

Android emulator

sdkmanager --list
this command will show you the list of available android system images. Install an android image of your choice. For example.

sdkmanager --install "system-images;android-29;default;x86"
Enter fullscreen mode Exit fullscreen mode

Then create an android emulator

avdmanager create avd -n <name> -k "system-images;android-29;default;x86"
Enter fullscreen mode Exit fullscreen mode

Put these line in your .bashrc/.zshrc

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/
Enter fullscreen mode Exit fullscreen mode

Accept all of licences by this command
flutter doctor --android-licenses

and run
flutter doctor

Everything should work now except the android studio.
Alt Text

if your licences are not accepted even after running flutter doctor --android-licences try these commands and then run flutter doctor --android-licences again.

sudo chown -R $(whoami) $ANDROID_SDK_ROOT
Enter fullscreen mode Exit fullscreen mode

if licences are still not accepted (happened to me) then try this.

sudo flutter doctor --android-licenses

Create and run new Flutter app

flutter create new_app
cd new_app
flutter run --debug
Enter fullscreen mode Exit fullscreen mode

Alt Text
To run your app on a your mobile phone you need to enable USB debugging. and connect your device to your laptop using a USB.

Linux is an amazing OS for Flutter development, but setting up Java, Android and the Android tool-cha...