Set up Android Studio on GCP VM instance

Nitin Tiwari
6 min readMay 18, 2024

--

This article extends the MobileLlama3 blog, walking you through setting up a Linux VM environment on GCP. It covers installing Android Studio and other necessary dependencies to convert the Llama3–8B-Instruct model for on-device deployment.

Introduction

In the previous article, we successfully quantized and converted the Llama3–8B-Instruct model to sharded weights. Now, we require installing specific dependencies and prerequisites to proceed with converting the model weights into a format compatible with Android.

Google Cloud Platform

Since I have a Windows machine, installing the necessary libraries and dependencies was a pain for me due to compatibility issues. Therefore, I decided to rent a Linux VM instance on GCP to avoid all those hassles.

Step 1: Create a VM instance on GCP

Go to Google Cloud Console, under Compute Engine, create a new Linux VM instance.

Create a VM instance on GCP

Configure the below settings:

  • Name: Assign some name to the VM instance. I’ve assigned “linux” to it.
  • Machine configuration: Under Compute optimized, select the C2 series.
  • Boot Disk: I’ve set this to 80 GB to ensure enough storage for the libraries and applications we’ll be installing. Since this is a completely fresh VM, we’ll need to install Python, Git, CMake, Android Studio, and everything else from scratch.
  • Firewall: Enable the HTTP and HTTPS traffic.

Step 2: Create a new Firewall Rule.

Apart from the settings done in Step 1, we also need to create a custom firewall rule to connect the VM instance through a remote desktop graphical interface tool like RealVNC Viewer. Click here to download it.

Go to Firewall Policies, and click Create Firewall Rule.

Create a new firewall rule
  • Name: Give a name to the firewall rule. I’ve named it as vnc-server.
  • Description: Some description such as “Connect to remote desktop”.
  • Network: default
  • Priority: 1000
  • Direction of traffic: Ingress
vnc-server firwall rule settings
  • Action on match: Allow
  • Target tags: vnc-server
  • Source IPv4 ranges: 0.0.0.0/0
  • Protocols and ports: Specified protocols and ports → Enable TCP → Port 5901
  • Enforcement: Enabled

Finally, click the Create button to create the vnc-server firewall rule.

Now, we need to add this firewall rule to the linux VM we created.

Click on the name of the VM instance i.e., linux.

Click on Edit button → Go to Network tags section and add the tag vnc-server → Save.

All configurations are now set up on the GCP side, and we’re ready to launch our VM. Click the SSH button to open the VM terminal directly in the browser.

Step 3: Installing necessary libraries and applications

(a) Update the Linux VM instance.

sudo apt-get update

(b) Install the LXDE desktop environment.

sudo apt-get install lxde

When the following screen appears, simply press the Enter key.

(c) Install the VNC server.

sudo apt-get install tightvncserver

(d) Once installed, type vncserver on terminal and configure password.

vncserver

(e) Configure the startup script to connect to the VM via the RealVNC Viewer remote desktop tool.

cd ~/.vnc
nano xstartup

# Type the below line --> Ctrl+O --> Enter --> Ctrl+X.
/usr/bin/startlxde
Configure xstartup script

(f) Install Python and manage permissions.

# Install Python3.
sudo apt-get install python3-pip

# Remove "EXTERNALLY-MANAGED" to allow pip to install packages.
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED

# Give all permissions to all directories and sub-directories inside /home.
sudo chmod -R 777 /home/

(g) Install Git.

sudo apt install git-all

Step 4: Open RealVNC Viewer and connect to the VM

Open RealVNC Viewer application on your local machine. In the VNC Server address bar, type ExternalIP:5901 where ExternalIP is the external IP address of your VM instance.

RealVNC Viewer

In the next screen, you’ll be prompted to enter the authentication password. This is the same password that you had set up in Step 3(d).

If everything goes well, you should be able to see the desktop screen of your VM instance graphically as follows.

Step 5: Install Android Studio on VM instance

We’re now ready to install Android Studio on our VM. Open web browser in the VM instance and download Android Studio .tar installer file.

Once downloaded, extract the .tar file.

# Go to the directory where Android Studio .tar installer is downloaded.
cd /home/tiwarinitin1999/Downloads

# Extract the .tar file.
tar -xvzf android-studio-2023.3.1.18-linux.tar.gz

Step 6: Open Android Studio

Navigate to the directory where Android Studio is extracted and run the studio.sh file.

Next is just the standard process of installing Android Studio.

Android Studio

Congratulations on successfully installing Android Studio and other dependencies on a GCP VM instance. I hope you learned something new from this article.

Head back to the MobileLlama3 blog for subsequent steps of converting and deploying the Llama3–8B-Instruct model on Android.

--

--