Skip to content

Commit 19cd656

Browse files
author
Iain Connor
committed
Tools
1 parent 3080f17 commit 19cd656

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

Dockerfile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Inspired by:
2+
# https://github.com/jangrewe/gitlab-ci-android/blob/master/Dockerfile
3+
# https://github.com/51systems/gitlab-ci-android/blob/master/Dockerfile
4+
# https://github.com/reddit/docker-android-build/blob/master/Dockerfile
5+
6+
FROM ubuntu:16.04
7+
MAINTAINER Iain Connor <[email protected]>
8+
9+
ENV DEBIAN_FRONTEND noninteractive
10+
11+
ENV VERSION_SDK_TOOLS "25.1.7"
12+
ENV VERSION_BUILD_TOOLS "24.0.2"
13+
ENV VERSION_TARGET_SDK "24"
14+
15+
ENV ANDROID_HOME "/sdk"
16+
ENV PATH "$PATH:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools"
17+
18+
# Install dependencies
19+
20+
RUN apt-get -qq update && \
21+
apt-get install -qqy --no-install-recommends \
22+
curl \
23+
html2text \
24+
openjdk-8-jdk \
25+
libc6-i386 \
26+
lib32stdc++6 \
27+
lib32gcc1 \
28+
lib32ncurses5 \
29+
lib32z1 \
30+
unzip \
31+
wget \
32+
build-essential \
33+
expect \
34+
file \
35+
libmagic1
36+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
37+
38+
# Fix certificates
39+
40+
RUN rm -f /etc/ssl/certs/java/cacerts; \
41+
/var/lib/dpkg/info/ca-certificates-java.postinst configure
42+
43+
# Install the SDK tools
44+
45+
ADD http://dl.google.com/android/repository/tools_r${VERSION_SDK_TOOLS}-linux.zip /tools.zip
46+
RUN unzip /tools.zip -d /${ANDROID_HOME} && \
47+
rm -v /tools.zip
48+
49+
# Install our helpers
50+
51+
COPY tools /usr/local/bin/tools
52+
RUN chmod +x /usr/local/bin/tools/agree-to-licenses.sh
53+
RUN chmod +x /usr/local/bin/tools/wait-for-emulator.sh
54+
55+
# And use them to install Android dependencies
56+
57+
RUN ["/opt/tools/android-accept-licenses.sh", "android update sdk --all --no-ui --filter \
58+
platform-tools, \
59+
android-${VERSION_TARGET_SDK}, \
60+
build-tools-${VERSION_BUILD_TOOLS}, \
61+
sys-img-armeabi-v7a-google_apis-${VERSION_TARGET_SDK}, \
62+
extra-android-m2repository, \
63+
extra-google-m2repository, \
64+
extra-android-support, \
65+
extra-google-google_play_services"]
66+
67+
# Create emulator
68+
69+
RUN echo "no" | android create avd \
70+
--force \
71+
--device "Nexus 5" \
72+
--name nexus5_${VERSION_TARGET_SDK} \
73+
--target android-${VERSION_TARGET_SDK} \
74+
--abi google_apis/armeabi-v7a \
75+
--skin WVGA800 \
76+
--sdcard 512M
77+
78+
# Boot up the emulator
79+
80+
RUN ["/bin/bash", "-c", "SHELL=/bin/bash emulator -avd nexus5_${VERSION_TARGET_SDK} -no-skin -no-audio -no-window & /usr/local/bin/tools/wait-for-emulator.sh"]
81+
RUN adb wait-for-device
82+
RUN android-start-emulator nexus5_${VERSION_TARGET_SDK} && adb -s emulator-5554 emu kill

tools/agree-to-licenses.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set timeout 1800
4+
set cmd [lindex $argv 0]
5+
set licenses [lindex $argv 1]
6+
7+
spawn {*}$cmd
8+
expect {
9+
"Do you accept the license '*'*" {
10+
exp_send "y\r"
11+
exp_continue
12+
}
13+
eof
14+
}

tools/wait-for-emulator.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set +e
4+
5+
bootanim=""
6+
failcounter=0
7+
timeout_in_sec=360
8+
9+
until [[ "$bootanim" =~ "stopped" ]]; do
10+
bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &`
11+
if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline"
12+
|| "$bootanim" =~ "running" ]]; then
13+
let "failcounter += 1"
14+
echo "Waiting for emulator to start"
15+
if [[ $failcounter -gt timeout_in_sec ]]; then
16+
echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator"
17+
exit 1
18+
fi
19+
fi
20+
sleep 1
21+
done

0 commit comments

Comments
 (0)