Getting Started with Flutter on Linux for Android [Beginner Tutorial]

Flutter is a cross platform and performant native mobile app framework by Google and can target Android and iOS at the moment. The language that comes with it is Dart, which originally made it into Chrome Canary as a possible JavaScript replacement or alternative.

In this post we’re going to have a look at how to set up a development environment for Flutter and Android. At the end of this post, you’ll have a working development environment on Ubuntu, Linux Mint or similar, including your first Flutter app running in an emulator and device.

Installing Flutter and Android Studio

The Flutter Linux Installation Docs are the starting point and take you through downloading the appropriate file:

# adapted
cd ~/Downloads
wget https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz
tar xf ~/Downloads/flutter_linux_v1.0.0-stable.tar.xz

Now you can add the flutter binaries to your PATH, either by running this in your terminal:

export PATH="$PATH:/home/$USER/Downloads/flutter/bin"

or by adding it to the configuration file of your shell permanently. Depending on which shell you use, these will typically be:

  • ~/.bashrc for bash
  • ~/.zshrc for zsh

Open the respective file and add around the bottom.

export PATH="$PATH:/home/$USER/Downloads/flutter/bin"

You can reload your config by running:

  • source ~/.zshrc
  • source ~/.bashrc

or restart your terminal.

You can verify your flutter installation with flutter doctor, the output should be something like:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Linux, locale en_US.UTF-8)
[✗] Android toolchain - develop for Android devices
    ✗ ANDROID_HOME = /home/jonathan/Android/Sdk
      but Android SDK not found at this location.
[!] Android Studio (not installed)
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

Installing Android Studio and Flutter Plugins

First, we’ll need to download Android Studio and unpack this into our Downloads or home folder. I have placed my unpacked version in /home/jonathan/android-studio. To start it I can run:

cd /home/jonathan/android-studio/bin
./studio.sh

This will open the IntelliJ based IDE for Android Studio and start off with a splash screen. After the IDE has started, just create a new Android project, because we want to head into the Tools menu and open the SDK Manager.

Inside the SDK Manager we want to navigate to the Plugins menu and press the Browse Repositories… In the following dialogue you can now search for Flutter and hit install, which should prompt you to install the Dart plugin as well.

Adding the Android Studio Home to your PATH

Now that we have the Android Studio installed, it should have created a directory in our home folder called Android, to add the tools and platform-tools that come with it, we need to add something like the following to our .zshrc or .bashrc. Remember to change the paths if you’re not called Jonathan 😉

export ANDROID_HOME="/home/jonathan/Android/Sdk"
export PATH="/home/jonathan/scripts:/home/jonathan/projects/go/bin:/home/jonathan/Downloads/flutter/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"

Remember to reload your shell config with source ~/[config name here].

Now to verify that we have installed the Android SDK correctly, let’s run flutter doctor again:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] Android Studio (version 3.2)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

After installing the Android SDK, you’ll have to agree to some license agreements via the CLI. Now we still have No devices available, let’s fix that with an Android Emulator.

Adding an Android Emulator

In Android Studio, head to Tools and then AVD Manager (Android Virtual Devices) and add a new emulator. This should be straight forward.

After you have gone through this process and started your emulator, you should no longer receive the warning that no devices are present by flutter doctor.

Troubleshooting the AVD

If you can’t add an AVD due to errors regarding /dev/kvm permission denied on Linux, you can try to install some additional dependencies and adding your user to the kvm group:

sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager
sudo adduser $USER kvm

NOTE: after running the adduser command you should restart your machine.

If you’re still facing trouble, there may be a BIOS setting which is not set correctly, for the most common BIOS versions you can see how to change it here: fedora wiki: BIOS setting for virtualisation

For GIGABYTE mainboards this setting is slightly hidden within Advanced CPU Core Settings and called SVM mode which needs to be enabled.

Enabling your Android Phone for Development

To set your phone up for app development, you’ll need to enable some developer settings, like explained by the Google Android Docs.

After this, if your phone is the target device for flutter and attached to your computer, it will automatically install the app and launch it when you use flutter run.

Creating your first Flutter App

For the next step you can either use Visual Studio Code or the Android Studio, as you wish. I’ll use vscode in the example:

  1. I create a directory where my flutter projects will live with cd ~/projects && mkdir flutter && cd flutter
  2. I create a new flutter project with flutter create test1
  3. I follow the instructions and run cd test 1 and flutter run
  4. The app should now appear in your AVD

To open your project with Visual Studio Code, change to your project directory with cd ~/projects/flutter/test1 && code .

Now you will be able to edit the flutter app and change the text labels or counter behaviour (try adding 3 at a time!).

If you want to integrate VSCode more closely with Flutter, make sure to install the Dart and Flutter plugins, which will enable you to create new projects or run your app from within Visual Studio Code.

That’s it! You’re now up and running with Flutter development for Android! Happy coding and remember to share your first app results!

PS: Thanks to some sub-reddits and Thomas for the review!

Rust Nightly or Stable with Rustup and “may not be used” error

When writing one of my pet projects or rather, a very simple automation matter in Rust, I fell into many pits. Usually full of snakes (of my own lack of knowledge of rust), but this one struck me as relatively interesting.

The stable compiler does not allow you to use unstable APIs/features. You have to use the nightly release branch.

If you know node, this is probably the equivalent of having to run V8 with harmony flags.

Rustup easily enables you to install the nightly branch of rust and to use it by default:

Continue reading “Rust Nightly or Stable with Rustup and “may not be used” error”

Upgrading XMR-Stak Miners for the Monero7 Protocol Update

If you’re mining Monero, you might have heard of the currency getting some bad press because several botnets pushed miners out to their clients. This is one of the reasons why the core team decided to upgrade the protocol. You can find their official statement on getmonero.org.

Continue reading “Upgrading XMR-Stak Miners for the Monero7 Protocol Update”

Goroutines, Channels and awaiting Asynchronously Operations in Go

Golang has fantastic support for actions that are supposed to happen concurrently (at the same time) without blocking the thread, they are called goroutines and are used by simply putting go in front of a function.

The functions prefixed with go will run “on their own” and the rest of your code will continue to run.

In order to gather results or returns from the functions, you commonly make use of a channel. Channels are the collecting “buckets” that will receive what your goroutines write to them.

Continue reading “Goroutines, Channels and awaiting Asynchronously Operations in Go”

WordPress Filters Example for Beginners

WordPress comes with a lot of built in amazingness, one of those are filters. You can filter a lot of different things that WordPress outputs into your theme or from your plugin that originate from another place.

That means you can add or remove something to all titles, category names or widgets. That might not seem incredibly useful at first, but if you for example want to add a text at the end of a blog post or page while using an already existing theme, it can be very nifty.

Continue reading “WordPress Filters Example for Beginners”

How To: Detect Ad Blockers (adblock, uBlock, etc)

As a blogger or any other kind of publisher, you might be interested in if the user accessing your page right now is using an ad blocker or not. You might want to do that to display a box that encourages them to disable their ad blocker, because you’re trying to make a living off of blogging or to make more conscious decisions about how you’re going to layout your page.

If a user has an adblocker installed, you don’t have to reserve the space in your layout for the ad units, so you might as well get rid of them, so in this post we’re going to have a look at how we can determine if a user has installed an ad blocker like Adblock, Adblock Plus or uBlock.

Continue reading “How To: Detect Ad Blockers (adblock, uBlock, etc)”

Creating a Chatbot for Slack with Node.js in 17 lines

Creating a chatbot for Slack, the easy to setup group chat for teams was surprisingly easy. In this post we’re going to go over creating a chat bot that can reply to queries and take an action on simple keywords.

We’re going to use a node module called BotKit, which will enable us to connect to Slack easily. Actually Botkit offers a GUI (paid plans) and also connects to Microsoft Teams, Spark, Twilio and even Facebook.

One of the things I like the most about it is that you can kind of build a bot once and then re-use components across different platforms, which is super cool.

This post is written with

  • node 9.3.0

but will probably be up and downwards compatible fairly far since the dependency has been around for a while.

Continue reading “Creating a Chatbot for Slack with Node.js in 17 lines”

Managing Dependencies with Govendor (Heroku, Dokku)

govendor is a dependency manager for Go. Go get gets you pretty far when it comes to installing dependencies at first, but when you want to deploy your project or when you want to pin the right version of your dependency it’s not necessarily appropriate to use.

With govendor you can, like with npm or other tools specify which version of your dependency your project uses, which is a huge benefit for systems that are required to be somewhat stable.

Continue reading “Managing Dependencies with Govendor (Heroku, Dokku)”

Heroku Alternative: Dokku

Dokku is advertising itself as a self hosted Platform as a service and it lives up to its promise. You can fairly easily deploy a range of applications like Ruby, Node.js, Go and so on. Basically everything beyond your standard PHP CMS like WordPress (but also that ;)).

Dokku is easy to install and maintain. Under the hood it uses docker containers to run your apps. Dokku also comes as a pre-built app as a one click installer on Digital Ocean*. Since Dokku is very easy to install, there’s a couple of alternatives for you, for example Linode* or Vultr*.

Note: Dokku recommends at least 1GB or RAM.

Continue reading “Heroku Alternative: Dokku”

WordPress .htaccess and Permalink Cheat Sheet

WordPress is still incredibly popular and sometimes you have a to move a WordPress installation or you want to change your permalink structure. Regardless of your motivation, you probably don’t want to hurt your SEO.

I’ve spent some time writing and testing .htaccess for Apache2 redirects recently, so I thought I’d share a list of commonly needed WordPress redirects using regular expressions or just removing segments.

By default I’ll assume you use a .htaccess file that looks something like this:

Continue reading “WordPress .htaccess and Permalink Cheat Sheet”