Setup Android Emulator on Ubuntu
If you're looking to set up an Android emulator on Ubuntu, follow these steps:
Requirement
Before proceeding with the emulator setup, ensure that you have Android Studio installed on your system. If you haven't installed Android Studio yet, you can refer to the guide on [setup-android-studio-for-ubuntu].
Getting Started
Option 1 - Launch Emulator from Android Studio
- Launch Android Studio on your Ubuntu system.
- From the Tools menu, select Device Manager.
- In the Device Manager, you will see the default device listed. You can select and launch it from there.
Option 2 - Launch Emulator from the Command Line
- Create a symbolic link for the emulator:
# For Mac
$ ln -s ~/Library/Android/sdk/tools/emulator /usr/local/bin/emulator
# For Ubuntu
$ ln -s ~/Android/Sdk/tools/emulator /usr/local/bin/emulator
# For x86
$ ln -s ~/Android/Sdk/tools/emulator-x86 /usr/local/bin/emulator-x86
- Add the following lines to your
.zshrc
file:
# Android
export ANDROID_HOME=~/Android/Sdk
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
- Update the configuration:
source ~/.zshrc
- Test the emulator command:
emulator -list-avds
$ Output
$ Pixel_3a_API_31.avd
- Launch the emulator:
cd ~/Android/Sdk/emulator
emulator -avd Pixel_3a_API_31 -netdelay none -netspeed full -feature -Vulkan;
Google Play Services
Option 1 - Setup Device from Android Studio
If you have already set up the device from Android Studio, you don't need to amend the config file. You can configure your device correctly directly from Android Studio.
During the device setup, search for an image with the Google Play icon. Select that image to set up the device with Google Play Services.
Option 2 - Install Google Play Services on Android Studio Emulator via OpenGApps
-
Download the Open GApps zip file from the Open GApps website. For example, the downloaded zip file could be
open_gapps-x86-11.0-pico-20220503.zip
. -
Extract the packages:
unzip open_gapps-x86-11.0-pico-20220503.zip 'Core/*'
rm Core/setup*
lzip -d Core/*.lz
for f in $(ls Core/*.tar); do
tar -x --strip-components 2 -f $f
done
- Start an emulator:
cd ~/Android/Sdk/emulator
emulator -avd Pixel_3a_API_31 -writable-system &
- Install the packages:
ANDROID_HOME/platform-tools/adb remount
ANDROID_HOME/platform-tools/adb push etc /system
ANDROID_HOME/platform-tools/adb push framework /system
ANDROID_HOME/platform-tools/adb push app /system
ANDROID_HOME/platform-tools/adb push priv-app /system
- Restart the emulator:
ANDROID_HOME/platform-tools/adb shell stop
ANDROID_HOME/platform-tools/adb shell start
Killing the Emulator
To kill the emulator, follow these steps:
- Print a list of your devices:
adb devices
- Kill the emulator using the
emu
command:
adb -s emulator-5432 emu kill
Troubleshooting
Cannot Open Webpages Correctly
Starting with API level 30, Chrome uses the Vulkan graphics library as its rendering backend, which may cause
compatibility issues on certain machines. If Chrome does not render correctly for you, try launching the emulator from
the command line with the -feature -Vulkan
flags:
emulator -avd avd_name [ {-option [value]} … ]
For example:
emulator -avd Pixel_3a_API_31 -netdelay none -netspeed full -feature -Vulkan;
These steps should help you set up and configure the Android emulator on your Ubuntu system. Enjoy developing and testing your Android applications!