Skip to content

Commit 2982ce5

Browse files
committed
Continuous integration with Travis and Docker, fixes #625
This is a first step to python-for-android continuous integration. It currently only verifies that p4a creates an APK by cross compiling a limited set of recipes. How it works; On git push Travis "executes" `.travis.yml` instructions: 1. the `before_install` section runs `docker build` to prepare the environment 2. the `script` section is the actual test, building the APK with `docker run` 3. based the exit status Travis build will be green or red For example editing `pythonforandroid/recipes/hostpython2/__init__.py` and introducing an error e.g. replace `-j5` with `--wrong-flag` would make it fail. Things to improve: - improve `.travis.yml` readability - test more recipes - bring Python3 and Crystax support - speed up build/run by caching downloads - and much more
1 parent cbad638 commit 2982ce5

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sudo: required
2+
3+
language: generic
4+
5+
services:
6+
- docker
7+
8+
before_install:
9+
- docker build --tag=p4a .
10+
11+
script:
12+
- docker run p4a /bin/sh -c 'uname -a'
13+
- docker run p4a /bin/sh -c '. venv/bin/activate && p4a apk --help'
14+
- docker run p4a /bin/sh -c '. venv/bin/activate && p4a apk --private testapps/testapp/ --package=com.github.kivy --name "Testapp" --version 0.1 --sdk_dir /opt/android/android-sdk/ --android_api 19 --ndk_dir /opt/android/android-ndk/ --ndk-version 16b --bootstrap=sdl2 --requirements=python2,kivy'

Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Dockerfile with:
2+
# - Android build environment
3+
# - python-for-android dependencies
4+
# Build with:
5+
# docker build --tag=p4a .
6+
# Run with:
7+
# docker run p4a /bin/sh -c '. venv/bin/activate && p4a apk --help'
8+
# Or for interactive shell:
9+
# docker run -it --rm p4a
10+
#
11+
# TODO:
12+
# - delete archives to keep small the container small
13+
# - setup caching (for apt, pip, ndk, sdk and p4a recipes downloads)
14+
FROM ubuntu:16.04
15+
16+
17+
# get the latest version from https://developer.android.com/ndk/downloads/index.html
18+
ENV ANDROID_NDK_VERSION="16b"
19+
# get the latest version from https://developer.android.com/studio/index.html
20+
ENV ANDROID_SDK_TOOLS_VERSION="3859397"
21+
22+
ENV ANDROID_HOME="/opt/android"
23+
ENV ANDROID_NDK_HOME="${ANDROID_HOME}/android-ndk" \
24+
ANDROID_SDK_HOME="${ANDROID_HOME}/android-sdk"
25+
ENV ANDROID_NDK_HOME_V="${ANDROID_NDK_HOME}-r${ANDROID_NDK_VERSION}"
26+
ENV ANDROID_NDK_ARCHIVE="android-ndk-r${ANDROID_NDK_VERSION}-linux-x86_64.zip" \
27+
ANDROID_SDK_TOOLS_ARCHIVE="sdk-tools-linux-${ANDROID_SDK_TOOLS_VERSION}.zip"
28+
ENV ANDROID_NDK_DL_URL="https://dl.google.com/android/repository/${ANDROID_NDK_ARCHIVE}" \
29+
ANDROID_SDK_TOOLS_DL_URL="https://dl.google.com/android/repository/${ANDROID_SDK_TOOLS_ARCHIVE}"
30+
31+
# install system dependencies
32+
RUN apt update && apt install --yes --no-install-recommends \
33+
python virtualenv python-pip wget curl lbzip2 patch
34+
35+
# build dependencies
36+
# https://buildozer.readthedocs.io/en/latest/installation.html#android-on-ubuntu-16-04-64bit
37+
RUN dpkg --add-architecture i386 && apt-get update && apt install --yes --no-install-recommends \
38+
build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 \
39+
libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev \
40+
openjdk-8-jdk unzip zlib1g-dev zlib1g:i386
41+
RUN pip install --upgrade cython==0.21
42+
43+
# download and install Android NDK
44+
RUN curl --progress-bar "${ANDROID_NDK_DL_URL}" --output "${ANDROID_NDK_ARCHIVE}" && \
45+
mkdir --parents "${ANDROID_NDK_HOME_V}" && \
46+
unzip -q "${ANDROID_NDK_ARCHIVE}" -d "${ANDROID_HOME}" && \
47+
ln -sfn "${ANDROID_NDK_HOME_V}" "${ANDROID_NDK_HOME}"
48+
49+
# download and install Android SDK
50+
RUN curl --progress-bar "${ANDROID_SDK_TOOLS_DL_URL}" --output "${ANDROID_SDK_TOOLS_ARCHIVE}" && \
51+
mkdir --parents "${ANDROID_SDK_HOME}" && \
52+
unzip -q "${ANDROID_SDK_TOOLS_ARCHIVE}" -d "${ANDROID_SDK_HOME}"
53+
54+
# update Android SDK, install Android API, Build Tools...
55+
RUN mkdir --parents "${ANDROID_SDK_HOME}/.android/" && \
56+
echo '### User Sources for Android SDK Manager' > "${ANDROID_SDK_HOME}/.android/repositories.cfg"
57+
RUN yes | "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" --licenses
58+
RUN "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "platforms;android-19"
59+
RUN "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "build-tools;26.0.2"
60+
61+
# install python-for-android from current branch
62+
WORKDIR /app
63+
COPY . /app
64+
RUN virtualenv --python=python venv && . venv/bin/activate && pip install -e .

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
python-for-android
22
==================
33

4+
|Build Status|
5+
6+
.. |Build Status| image:: https://secure.travis-ci.org/kivy/python-for-android.png?branch=master
7+
:target: https://travis-ci.org/kivy/python-for-android
8+
49
python-for-android is a packager for Python apps on Android. You can
510
create your own Python distribution including the modules and
611
dependencies you want, and bundle it in an APK along with your own code.

0 commit comments

Comments
 (0)