Sunday, December 27, 2020

Flutter - Setup - Linux Desktop Development

If you have installed flutter from snap previously. Please remove it:

1 sudo snap remove flutter


 For Linux desktop development, you need the following in addition to the Flutter SDK:

  1. Clang

  2. CMake

  3. GTK development headers

  4. Ninja build

  5. pkg-config

  6. libblkid

  7. liblzma

Step 1: Pls install these dependencies using:

1 sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev libblkid-dev liblzma-dev

Also, check for the existence of open jdk 8:

1 2 3 4 $ java -version openjdk version "1.8.0_275" OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01) OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

If Open Jdk is not available install it using:

1 2 sudo apt-get install openjdk-8-jdk sudo update-alternatives --config java

After running “sudo update-alternatives --config java” we have to select the number which contain jdk-8.

Export the environment variable - JAVA_HOME as follows:

1 export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

Also, add the above line as the last line in the file: ~/.bashrc


Step 2: Change directory to /usr/local:

1 cd /usr/local

Step 3: Get the Flutter repo from Github using the following command:

1 sudo git clone https://github.com/flutter/flutter.git

Step 4: Check the current user using the command:

1 2 $ whoami ubuntu

Since, Our login user is: ubuntu

Step 5: Change the ownership of the flutter repo directory to current user: ubuntu

1 sudo chown -R ubuntu:ubuntu /usr/local/flutter

Step 6: Add the following line to the file ~/.bashrc atthe end of the file

1 2 3 vi ~/.bashrc ### add below line at the end of the file export PATH="$PATH:/usr/local/flutter/bin"

Step 7: Update the Path Variable in the current terminal:

1 export PATH="$PATH:/usr/local/flutter/bin"

Step 8: Change the current branch to master and upgrade:

1 2 flutter channel master flutter upgrade -f

Step 9: Run the following command to see if there are any dependencies you need to install to complete the setup

1 flutter doctor

Step 10: Optionally, pre-download development binaries:

The flutter tool downloads platform-specific development binaries as needed. For scenarios where pre-downloading these artifacts is preferable (for example, in hermetic build environments, or with intermittent network availability), iOS and Android binaries can be downloaded ahead of time by running:

1 flutter precache

Step 11: Enable Linux Deskop

1 2 flutter config --enable-linux-desktop

Step 12: Step a directory to store flutter projects:

1 2 mkdir /opt/flutter-projects/ cd /opt/flutter-projects/

Step 13: Create our first flutter app using the command:

1 2 flutter create myapp cd /opt/flutter-projects/myapp

Step 14: Run our flutter app:

1 2 flutter create . flutter run -d linux


 References: