Setting up Flutter for Android on Linux without Android Studio

The official Flutter docs may talk about setting up Android SDK through Android Studio, but some people just don't want to use it. That's why here you'll find out how to set it up without it!

Setting up Flutter for Android on Linux without Android Studio
Photo by Roman Synkevych / Unsplash

So you've read up about Flutter and felt like it would be cool to try out the cross-platform development yourself. Naturally, you want to make it work on mobile, so you stumble upon the official tutorial on how to set up your environment for Android development. As you've already been using VS Code for most stuff, you decide to use it for Flutter too, after all it has an official extension.

But what is this? To set up Android SDK, you should install Android Studio? What a bummer! Well, if you're like me and don't want to download a whole IDE just to manage SDKs, I've prepared a quick tutorial to install Flutter and SDKs manually on most Linux distros.

Don't install Flutter globally

If you're not planning on collaborating with other people on your code, you can safely ignore this section. In case you are, think about this: your Flutter installation does not auto-update itself, only when you run the flutter upgrade command. And when you run the upgrade command, that doesn't mean your colleagues will upgrade too. This can cause confusion when you start implementing features that are not available on older versions of Flutter, especially if you use other channels than stable.

That's where FVM, Flutter Version Manager, steps in. FVM manages Flutter installations for you, meaning you can use different versions of Flutter in different projects. FVM inserts a file that asserts the versions that should be use, meaning others can easily install the same version you use. See below how easy it is to get a version running:

Getting the Android SDK

💡
Tip: Most distros may already have the SDK/tools included in their package repos, which can significantly save set-up time (for example Arch Linux). Check if your distro also doesn't have them, because this will be a general-purpose tutorial.

The SDK itself is managed through a tool called sdkmanager. This tool can be downloaded from the Android Developers page. Download it to a new folder, for example android_sdk, and unzip it. Because the SDK manager expects to be inside a folder called latest, create a new folder with such name and move the contents of the extracted cmdline-tools folder into it:

mkdir android_sdk
mv ../cmdtools.zip ./ # adapt to your own path
unzip cmdtools.zip
mkdir latest
mv cmdline-tools/* latest/

After that, move the latest folder back to the cmdline-tools folder and add the android_sdk/cmdline-tools/latest/bin folder to PATH, so we can use the sdkmanager utility:

mv latest cmdline-tools
export PATH=$PATH:/home/johnp/android_sdk/cmdline-tools/latest/bin # change /home/... to the full path where you extracted the zip
To have the PATH persist after closing the terminal, make sure to add the export command to your /.bashrc, ~/.zshrc or similar file

Now if you enter sdkmanager --list, you'll see all the packages we can install. But what do we install?

  • platform-tools include the Android Developer Bridge (adb, used to connect to the device)
  • platforms to install the specified Android platform; for example "platforms;android-34" installs Android with API level 34 (e.g. Android 14)
If you get an error about missing Java, make sure to install the Java Development Kit (JDK), not Java Runtime Environment (JRE), as the development kit is also required by Flutter to build APKs

You can install these packages by simply running the command sdkmanager "platform-tools" "platforms;android-34", replacing the versions (behind ;) as appropriate.

If we run fvm flutter doctor and encounter something like ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses, simply run the said command and accept the licenses (if you dare) to resolve it.

And now you should be good to go!