DEV Community

Design Dev
Design Dev

Posted on • Edited on

Install Flutter SDK, Android SDK, and Start Android Emulator in WSL

In today’s rapidly evolving tech landscape, mobile app development has become a crucial skill for developers. Flutter, Google’s open-source UI software development toolkit, has gained immense popularity for its ability to create natively compiled applications for mobile, web, and desktop from a single codebase. This guide aims to walk you through the comprehensive process of setting up the Flutter SDK, installing the Android SDK using command line tools, and running an Android emulator on your system. Whether you are a beginner or an experienced developer, this step-by-step tutorial will help you get started with Flutter development in no time.

1. Verify Required Tools

Ensure the following tools are installed:
which bash file mkdir rm which
Expected output:

/bin/bash
/usr/bin/file
/bin/mkdir
/bin/rm
which: shell built-in command
Enter fullscreen mode Exit fullscreen mode

2. Installed Required Packages

Update and install necessary packages:

sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa
Enter fullscreen mode Exit fullscreen mode

3. Install Flutter in VS Code

  1. Launch VS Code.
  2. Open the Command Palette: Control + Shift + P.
  3. Type flutter.
  4. Select Flutter: New Project.
  5. VS Code will prompt you to locate the Flutter SDK.
  • If you have the Flutter SDK installed, click Locate SDK.

  • If not, click Download SDK.

If you could not create project from vscode check the instruction given in this page: Download then install Flutter

4. Download Command Line Tools

  1. Create necessary directories and download the tools:
mkdir -p ~/Android/Sdk/cmdline-tools
cd ~/Android/Sdk/cmdline-tools
wget https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip
unzip commandlinetools-linux-7302050_latest.zip
mv cmdline-tools latest
Enter fullscreen mode Exit fullscreen mode

5. Set Up Environment Variables

  • Open your profile file (e.g., .bashrc or .zshrc):
    nano ~/.bashrc

  • Add the following lines:

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH
Enter fullscreen mode Exit fullscreen mode
  • Apply the changes: source ~/.bashrc

6. Install Java

  • Install OpenJDK 17:
    sudo apt install openjdk-17-jdk

  • Determine the Java installation path:
    sudo update-alternatives --config java

  • Set JAVA_HOME and update PATH:
    nano ~/.bashrc

  • Add the following lines:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
Enter fullscreen mode Exit fullscreen mode
  • Apply the changes:
    source ~/.bashrc

  • Verify Java installation:
    java -version

7. Install Android SDK Packages

  1. Navigate to the command line tools directory: cd ~/Android/Sdk/cmdline-tools/latest/bin
  2. Install required SDK packages: ./sdkmanager --install "platform-tools" "platforms;android-30" "build-tools;30.0.3" "emulator" "system-images;android-30;google_apis;x86_64"
  3. Accept Licenses: ./sdkmanager --licenses

8. Create and Start an AVD

  1. Create and AVD:
    avdmanager create avd -n my_avd -k "system-images;android-30;google_apis;x86_64" --device "pixel"

  2. Start the emulator:
    cd ~/Android/Sdk/emulator
    ./emulator -avd my_avd


Troubleshooting

Error: libpulse.so.0 not found
sudo apt install libpulse0
KVM permission error
sudo chown username /dev/kvm


Running Android Emulator in VS Code

  1. Run Emulator from Command Line:
    cd ~/Android/Sdk/emulator
    ./emulator -avd my_avd

  2. Select Device in VS Code:

  • Open Command Palette: Ctrl + Shift + P
  • Select Flutter: Select Device
  • Choose your running emulator from the list

These steps should help you set up Flutter and the Android SDK, create and start an Android emulator, and integrate it with VS Code.


Setting up a Flutter development environment can seem daunting at first, but with the right tools and a systematic approach, it becomes a straightforward process. By following this guide, you have equipped yourself with the knowledge to install the Flutter SDK, configure the Android SDK, and run an Android emulator on WSL. This powerful setup will enable you to develop, test, and deploy high-quality mobile applications efficiently. As you continue your journey in mobile app development, remember that the community and resources available are vast and supportive. Happy coding!

Reference: Start building Flutter Android apps on Linux
(https://docs.flutter.dev/get-started/install/linux/android)

Top comments (1)

Collapse
 
ejeker profile image
Eric Jeker

Worked like a charm, thank you. I had both issues you describe in Troubleshooting. You might as well add them in the step by step as they are idempotent.