Android
This guide will help build Android projects on Semaphore.
Overview
Semaphore provides a set of Docker images tailored for Android developers. These pre-built images ship with the Android SDK and other common build tools for Android projects.
These images can be used both for Android and React Native projects. Semaphore also supports using Android emulators inside CI jobs.
How to use Android containers
Use Docker Environments to run jobs inside pre-built Android images.
- Editor
- YAML
To use an Android container in your pipeline, follow these steps:
-
Open the pipeline
-
Select "Docker Containers" in Environment Type
-
Choose a machine
-
Type the name of the Image. Use one of the available Android SDK images
-
Configure your jobs
-
Press Run the workflow
To configure your Android container using YAML, follow these steps:
-
Open the pipeline file
-
Type the agent definition: select a machine
type
andos_image
-
Add a
containers
listAndroid containersversion: v1.0
name: Initial Pipeline
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
containers:
- name: main
image: 'registry.semaphoreci.com/android:34'
blocks:
- name: 'Block #1'
dependencies: []
task:
jobs:
- name: 'Job #1'
commands:
- checkout -
The first item
name: main
and inimage
select one of the available Android SDK images -
Save the file and push it to the repository
Example for React Native
This section shows how to configure a pipeline to build and test a React Native project using Android containers.
- Editor
- YAML
-
Use an Android container. You need one of the image variants that ship with Node.js, e.g.
android:34-node
-
Create a Build/Install block with the following commands
checkout
cache restore
npm install
cache store -
Create a second test block with the following prologue. This starts the Android emulator
checkout
sdkmanager "platform-tools" "platforms;android-34" "emulator"
sdkmanager "system-images;android-34;default;armeabi-v7a"
echo no | avdmanager create avd -n Nexus_S_API_34 -k "system-images;android-34;default;armeabi-v7a" --device "Nexus S" -
Type the following commands in the test job
cache restore
npm test -
Optionally, add more test jobs as needed
-
Press Run the workflow
- Open the pipeline file
- Configure the Android container
- Create a Build/Install block to install dependencies
- Add a second block to run your tests
- Save your file and push it to the repository
version: v1.0
name: React Native example
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
# Use an image with Node.js for React Native
containers:
- name: main
image: 'registry.semaphoreci.com/android:29-node'
blocks:
# Install block
- name: Install
task:
jobs:
- name: npm install
commands:
- checkout
- cache restore
- npm install
- cache store
# Test block
- name: Test
task:
# Prologue starts emulator
prologue:
commands:
- checkout
- sdkmanager "platform-tools" "platforms;android-34" "emulator"
- sdkmanager "system-images;android-34;default;armeabi-v7a"
- echo no | avdmanager create avd -n Nexus_S_API_34 -k "system-images;android-34;default;armeabi-v7a" --device "Nexus S"
# Test jobs
jobs:
- name: Run tests
commands:
- cache restore
- npm test
Building custom images
You can find the pre-build Android images in the Semaphore Container Registry.
The image definition and Dockerfiles for these images can be found in the repository semaphoreci/docker-images. Clone this repository to build your own image variants.
There are Docker images for each recent version of Android. There are also variants with Node.js preinstalled for React Native development:
android:<version>
: basic image with development utilitiesandroid:<version>-node
: basic image extended with Node.jsandroid:<version>-flutter
: basic image extended with Flutter toolchain
Android SDK images
These are the pre-built Android images available:
android:34
android:34-node
android:34-flutter
android:33
android:33-node
android:33-flutter
android:31
android:31-node
android:31-flutter
android:30
android:30-node
android:30-flutter
android:29
android:29-node
android:29-flutter
android:28
android:28-node
android:28-flutter
android:27
android:27-node
android:27-flutter
android:26
android:26-node
android:26-flutter
android:25
android:25-node
android:25-flutter
android:24
android:24-node
android:23
android:23-node
Pre-installed software
- ARM simulator (libqt5widgets5)
- Google Cloud SDK
- apt
- apt-transport-https
- build-essential
- bzip2
- ca-certificates
- curl
- docker
- docker-compose
- git
- gnupg
- gradle
- gzip
- jq
- lftp
- locales
- lsb-release
- maven
- mercurial
- net-tools
- netcat
- openssh-client
- parallel
- ruby 2.6.1
- software-properties-common
- sudo
- tar
- tree
- unzip
- vim
- wget
- xvfb
- zip