DEV Community

Cover image for Configure Flutter development environment on Manjaro/Arch linux.
Awais Iqbal
Awais Iqbal

Posted on • Updated on

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 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 these commands.



      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 these lines 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 Flutter 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 /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 we have 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 lines 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.


 flutter doctor --android-licenses

Enter fullscreen mode Exit fullscreen mode

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.

Top comments (8)

Collapse
 
2kabhishek profile image
Abhishek Keshri

on arch linux you have a simpler tool for managing the java version: archlinux-java

to sert the default java version, you can just use:

sudo archlinux-java set java-8-openjdk/jre   
Enter fullscreen mode Exit fullscreen mode

Great post btw, kudos!

Collapse
 
ortonomy profile image
๐Ÿ…–๐Ÿ…ก๐Ÿ…”๐Ÿ…–๐Ÿ…ž๐Ÿ…ก๐Ÿ…จ ๐Ÿ…ž๐Ÿ…ก๐Ÿ…ฃ๐Ÿ…ž๐Ÿ…

you can just install Android Studio from the AUR on arch yay -S android-studio and let that manage the android SDK and everything else. Moreoever, make sure you install the android SDK command line tools (CLI) or you won't be able to accept the android licenses.

Collapse
 
masterbrian99 profile image
pasindu p konghawaththa

great post.thank you

Collapse
 
wjpm profile image
William M.

Your post helped me a lot! Thanks!
In my case I still needed to run the following commands:
yay -S android-sdk-cmdline-tools-latest
yay -S ninja
yay -S cmake

Collapse
 
rxzor profile image
mystic rxzor

nice

Collapse
 
tashima42 profile image
Pedro Tashima

Thanks! Helped me a lot.

Collapse
 
kreezen profile image
kreezen

great post. good info on the User permissions, very helpful.

Collapse
 
muhammadabubakr profile image
frostywolf

great post but haven't you complicated the user permissions a little bit