Lucas LannesPosted on 3/18/2025

Running the Android Emulator on CI/CD Pipelines

#androidemulator#cicd#mobiledevelopment#androiddevelopment#devops

Create the Android emulator

# Install required packages to create and run the Android emulator
echo "y" | sdkmanager --install 'system-images;android-33;default;x86_64'

# Create the Android emulator
echo "y" | avdmanager create avd -n android -d "$ANDROID_EMULATOR" -k 'system-images;android-33;default;x86_64' --force

Replace $ANDROID_EMULATOR with the desired device such as 4.65in 720p (Galaxy Nexus), pixel_2, Nexus 10 etc.

You can check the available devices using the command avdmanager list device.

The android after -n is a custom name to the Android Virtual Device.

The echo "y" will automatically answer "yes" to any prompt during the command execution, for example, to accept Android SDK licenses and to confirm the Android Virtual Device creation.

Change android-33 to any Android API Level, but be careful because some versions can not work as expected or will need additional configuration.

Change default to google_apis if you need Play Store (Google Play) to be installed on the Android emulator, but be careful because it can't work in some situations.

Run the Android emulator

nohup emulator -avd android -no-snapshot -no-window -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 > /dev/null 2>&1 &

The android after -avd is the custom name given to the Android Virtual Device in the creation step.

The nohup in the beginning allows the command to continue running even if the terminal is closed.

The & in the end allows the command to continue running in the background.

Change the -m 2048 to the total amount of RAM nedeed for your use case.

If you're running on GitHub-hosted larger Linux runners, you need to enable hardware acceleration.

You can also try to run the Android emulator using this bash script that will check hardware acceleration.

Check the Android emulator

Before using the emulator, it's better to first check if it booted successfully.

adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d "\r") ]]; do sleep 1; done; input keyevent 82'
adb devices

Install an application in Android emulator

adb install "$APP_APK_PATH"

Replace $APP_APK_PATH with the path to the .apk file.

Run Android emulator on CI/CD pipelines

Below is the complete solution that will work on macOS agents in CI/CD environments.

# Install required packages to create and run the Android emulator
echo "y" | sdkmanager --install 'system-images;android-33;default;x86_64'

# Create the Android emulator
echo "y" | avdmanager create avd -n android -d "$ANDROID_EMULATOR" -k 'system-images;android-33;default;x86_64' --force

# Run the Android emulator
nohup emulator -avd android -no-snapshot -no-window -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 > /dev/null 2>&1 &

# Check the Android emulator
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d "\r") ]]; do sleep 1; done; input keyevent 82'
adb devices

# Install an application in Android emulator
adb install "$APP_APK_PATH"

The commands above were tested in Azure Pipelines running on macOS-14 agent.

References

Read next

Lucas LannesPosted on 3/17/2025

Running the iOS Simulator on CI/CD Pipelines

#iosdevelopment#xcode#iossimulator#swift#cicd