Setting up flutter without Android studio
Tags: beginners, flutter, vscode, linux
Published: 2019-09-17 21:05:28

Sometimes due the hardware constraints or some other reasons developer will prefer light weight solution rather than Big Bulky Android Studio. So heres a good news for you in this article we will configure visual studio code to work with flutter without android studio. We are using ubuntu 19.04 as operating system but you can choose choice of your linux distros. So lets get started....

# Packages we required
1. [Android command line tools](https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip)
2. [Flutter Binaries](https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.9.1+hotfix.2-stable.tar.xz)
3. [Gradle build](https://downloads.gradle-dn.com/distributions/gradle-5.6.2-bin.zip)
4. OpenJDK 8 

# Installing Packages
We are installing it by following below steps respectively:

1. Navigate to folder where you downloaded your binaries.
2. Extract it and move it to relevant location.
3. Set up path and refresh .profile file to access utilities.

# Installing Packages
> To set up path open profile type in terminal 
> $ gedit ~/.profile 

### Android tools
```
$ unzip sdk-tools-linux-4333796.zip
$ mkdir Android
$ mv tools/ Android/
$ sudo mv Android/ /usr/lib 
```

```sh
#android home
export ANDROID_HOME=/usr/lib/Android
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

#android sdk root
export ANDROID_SDK_ROOT=/usr/lib/Android
export PATH=$ANDROID_SDK_ROOT:$PATH
```
### Flutter
```
$ tar xvf flutter_linux_v1.9.1+hotfix.2-stable.tar.xz
$ sudo mv flutter/ /usr/lib
```

```sh
#flutter
export FLUTTER_HOME=/usr/lib/flutter
export PATH=$FLUTTER_HOME/bin:$PATH
```
### Gradle
```
$ unzip gradle-5.6.2-bin.zip
$ mkdir gradle
$ mv gradle-5.6.2/ gradle/
$ sudo mv gradle/ /opt
```

```sh
#gradle
export GRADLE_HOME=/opt/gradle/gradle-5.6.2
export PATH=$GRADLE_HOME/bin:$PATH
```
### OpenJDK 8
- Open synaptic package manager if you don't have it install via 
```
$ sudo apt install synaptic
```
- Type in OpenJDK 8 to search bar.
- Select
  1. openjdk-8-jdk
  2. openjdk-8-jdk-headless
  3. openjdk-8-jre
  4. openjdk-8-jre-headless
- Apply and wait for install. Don't worry it will set up environment variable for you automatically.
 
> Our installation of packages is done use subsequent command to refresh .profile
> $ . ~/.profile

# Setting up Android environment
For setting Android environment you have to download following packages. I'm Downloading latest one as the date of publishing but you can download many system images to support wide array of devices using sdkmanager. 
> Note: If you're facing issue with sdkmanager as Warning: Could not create settings then open up terminal and type `$sdkmanager --sdk_root=${ANDROID_HOME} tools` this will upgrade binaries to latest and everything will works as expected.

```
$ sdkmanager "system-images;android-29;google_apis;x86_64"
$ sdkmanager "platforms;android-29"
$ sdkmanager "platform-tools"
$ sdkmanager "patcher;v4"
$ sdkmanager "emulator"
$ sdkmanager "build-tools;29.0.2"
```
Accept all licenses using 
> sdkmanager --licenses

# Setting up flutter config
Update flutter config and set path to android sdk directory where it is installed.

```
$ flutter config --android-sdk /usr/lib/Android
```
You have to install [flutter extension](https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter) in visual studio code in order use flutter.

# creating Emulator
Create emulator with name pixel or choose the name you want
```
$ avdmanager -s create avd -n pixel -k "system-images;android-29;google_apis;x86_64"
```
Create emulator using existing devices features
```
$ avdmanager -s create avd -n pixel -k "system-images;android-29;google_apis;x86_64" -d 19
```

you can get list of exting devices using
```
$ avdmanager list
```

# Moment of truth
```
$ flutter doctor -v
```
> This command should give all green and ok except android studio path.

# Run emulator
```
$ flutter emulator --launch pixel
```

Here's an image in action:
![Emulator](https://thepracticaldev.s3.amazonaws.com/i/nfjq2lqvu0kssevcqdg2.png)