Skip to content

Instantly share code, notes, and snippets.

@mrverdant13
Created August 10, 2021 03:29
Show Gist options
  • Save mrverdant13/ed9f353e595daf9e3574ad35924faadb to your computer and use it in GitHub Desktop.
Save mrverdant13/ed9f353e595daf9e3574ad35924faadb to your computer and use it in GitHub Desktop.
Use Flutter with WSL
#!/usr/bin/env bash
# 1
# Install the required GNU C Library and Java Dev Kit
# The especific packages may vary depending on your WSL distribution (these ones work for Ubuntu).
sudo apt-get install -y libc6-dev-i386 lib32z1 openjdk-8-jdk
# 2
# Make the JDK globally accessible.
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
# 3
# Automate the step 2 to be executed on every terminal startup.
# This command appends the commands used in the step 2 to the end of the `~/.bashrc` file.
# export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
# export PATH=$JAVA_HOME/bin:$PATH
printf "\n\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport PATH=\$JAVA_HOME/bin:\$PATH" >> ~/.bashrc
# 4
# Install `unzip` and `zip` packages.
sudo apt-get install unzip zip
# 5
# Go to home.
# Alternatively `cd $HOME`.
cd ~
# 6
# Download the Android command line tools.
# You can check the latest version at https://developer.android.com/studio.
wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
# 7
# Unzip the command line tools in the `Android` folder (it is created if it does not exist).
unzip commandlinetools-linux-7583922_latest.zip -d Android
rm commandlinetools-linux-7583922_latest.zip
# 8
# Relocate the unzipped folder.
# The reason why we need to do this is detailed here: https://stackoverflow.com/a/65262939/9783282
# The expected result is `~/Android/cmdline-tools/tools`
mv cmdline-tools tools
mkdir cmdline-tools
mv tools cmdline-tools/tools
# 9
# Install base packages for the Android SDK.
# The packages might change according to Flutter requirements.
cd Android/cmdline-tools/tools/bin
./sdkmanager --install "platform-tools" "platforms;android-26" "build-tools;26.0.3"
# 10
# Make the Android-regarding tools globally accessible.
export ANDROID_HOME=~/Android
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
# 11
# Automate the step 10 to be executed on every terminal startup.
# This command appends the commands used in the step 10 to the end of the `~/.bashrc` file.
# export ANDROID_HOME=~/Android
# export PATH=$ANDROID_HOME/tools:$PATH
# export PATH=$ANDROID_HOME/platform-tools:$PATH
printf "\n\nexport ANDROID_HOME=~/Android\nexport PATH=\$PATH:\$ANDROID_HOME/tools\nexport PATH=\$PATH:\$ANDROID_HOME/platform-tools" >> ~/.bashrc
# 12
# Update all Android SDK packages.
sdkmanager --update
# 13
# Install Flutter.
# It is recommended to install Flutter manually in the home directory (`~` or `$HOME`).
# https://flutter.dev/docs/get-started/install/linux#install-flutter-manually
# 14
# Make Flutter globally accessible.
# This command assumes that Flutter was installed within the home directory.
export PATH=~/flutter/bin:$PATH
# 15
# Automate the step 14 to be executed on every terminal startup.
# This command appends the commands used in the step 14 to the end of the `~/.bashrc` file.
# export PATH=~/flutter/bin:$PATH
printf "\n\nexport PATH=~/flutter/bin:\$PATH" >> ~/.bashrc
# 16
# Install gradle
# You can check the latest version at https://gradle.org/install/
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install gradle 7.1.1
gradle -v
# Now you can use Flutter with WSL!!!
# Test it out with `flutter doctor`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment