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
Installing Flutter
yay -S flutter
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
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/
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
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
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"
Then create an android emulator
avdmanager create avd -n <name> -k "system-images;android-29;default;x86"
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/
Accept all of licences by this command
flutter doctor --android-licenses
and run
flutter doctor
Everything should work now except the android studio.
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
if licences are still not accepted (happened to me) then try this.
flutter doctor --android-licenses
Create and run new Flutter app
flutter create new_app
cd new_app
flutter run --debug
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)
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:
Great post btw, kudos!
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.great post.thank you
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
nice
Thanks! Helped me a lot.
great post. good info on the User permissions, very helpful.
great post but haven't you complicated the user permissions a little bit