Cleanup: Improve (Android) Build Scripts.

Add a script for building the Android APK in the docker container.
Also make some improvements to the Windows build scripts, and update the
documentation for both builds.

Signed-off-by: Michael Keller <mikeller@042.ch>
This commit is contained in:
Michael Keller 2024-04-30 16:40:02 +12:00 committed by Michael Keller
parent 3153a139b3
commit 5ac1922d84
5 changed files with 92 additions and 49 deletions

View file

@ -1,49 +1,28 @@
# Over-simplistic instructions to building the Android package from source # Instructions for building the Android package from source
## In a Container ## In a Container
The easiest way to build things is using our container. The following script will download and build the dependencies on the first run of the container, and from there on in re-use the same container to speed up build time: The easiest way to build a .apk package for Android is to use
our own docker image that has all of the build components
pre-assembled.
All it takes is this:
```.sh ```.sh
#!/bin/bash export GIT_AUTHOR_NAME=<your name>
export GIT_AUTHOR_EMAIL=<email to be used with github>
# Change these to match your setup cd /some/path
SUBSURFACE_ROOT=<root directory of your local subsurface repository> git clone https://github.com/subsurface/subsurface
GIT_NAME="<name to use in git>" cd subsurface
GIT_EMAIL="<email to use in git>" git submodule init
git submodule update
CONTAINER_NAME=android-builder-docker ./packaging/android/docker-build.sh
# Check if our container exists
CONTAINER_ID=$(docker container ls -a -q -f name=${CONTAINER_NAME})
# Create the image if it does not exist
if [[ -z "${CONTAINER_ID}" ]]; then
docker create -v ${SUBSURFACE_ROOT}:/android/subsurface --name=${CONTAINER_NAME} subsurface/android-build:5.15.2 sleep infinity
fi
docker start ${CONTAINER_NAME}
BUILD_PARAMETERS=""
if [[ -n "${CONTAINER_ID}" ]]; then
BUILD_PARAMETERS="-quick"
else
# Prepare the image for first use
# Set the git id
docker exec -t ${CONTAINER_NAME} git config --global user.name "${GIT_NAME}"
docker exec -t ${CONTAINER_NAME} git config --global user.email "${GIT_EMAIL}"
fi
# Build. Do not rebuild the dependencies if this is not the first build
docker exec -e OUTPUT_DIR="/android/subsurface/android-debug" -t ${CONTAINER_NAME} /bin/bash -x ./subsurface/packaging/android/qmake-build.sh ${BUILD_PARAMETERS}
# Stop the container
docker stop ${CONTAINER_NAME}
``` ```
_Caveat:_ With this build script `libdivecomputer` is pulled from git in the version specified in the submodule, so if you have changed `libdivecomputer` make sure to commit any changes and update the git submodule version before building. _Caveat:_ With this build script `libdivecomputer` is pulled from git in the version specified in the submodule, so if you have changed `libdivecomputer` make sure to commit any changes and update the git submodule version before building.
This will result in Subsurface-mobile-VERSION.apk to be created in /some/path/subsurface/output/android/.
## On a Linux host ## On a Linux host
@ -102,6 +81,6 @@ your attached device:
``` ```
Note that since you don't have the same signing key that I have, Note that since you don't have the same signing key that I have,
you'll have to uninstalled the 'official' Subsurface-mobile binary in you'll have to uninstall the 'official' Subsurface-mobile binary in
order for this to work. And likewise you have to uninstall yours order for this to work. And likewise you have to uninstall yours
before you'll be able to install an official binary again. before you'll be able to install an official binary again.

View file

@ -0,0 +1,62 @@
#!/bin/bash
#
# Build the Subsurface Android APK in a Docker container
#
croak() {
echo "$0: $*" >&2
exit 1
}
CONTAINER_NAME=subsurface-android-builder
pushd .
cd "$(dirname "$0")/../.."
SUBSURFACE_ROOT="${PWD}"
popd
OUTPUT_DIR=output/android
CONTAINER_ROOT_DIR=/android
CONTAINER_SUBSURFACE_DIR=${CONTAINER_ROOT_DIR}/subsurface
LOGIN_USER=$(id -u)
LOGIN_GROUP=$(id -g)
FULL_USER=${LOGIN_USER}:${LOGIN_GROUP}
# Check if our container exists
CONTAINER_ID=$(docker container ls -a -q -f name=${CONTAINER_NAME})
# Create the container if it does not exist
if [[ -z "${CONTAINER_ID}" ]]; then
# We'll need these later
if [ -z ${GIT_AUTHOR_NAME+X} -o -z ${GIT_AUTHOR_EMAIL+X} ]; then
croak "Please make sure GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL are set for the first run of this script."
fi
docker create -v ${SUBSURFACE_ROOT}:${CONTAINER_SUBSURFACE_DIR} --name=${CONTAINER_NAME} subsurface/android-build:5.15.2 sleep infinity
fi
# Start the container
docker start ${CONTAINER_NAME}
BUILD_PARAMETERS=""
if [[ -z "${CONTAINER_ID}" ]]; then
# Prepare the image for first use
docker exec -t ${CONTAINER_NAME} groupadd $(id -g -n) -o -g ${LOGIN_GROUP}
docker exec -t ${CONTAINER_NAME} useradd $(id -u -n) -o -u ${LOGIN_USER} -g ${LOGIN_GROUP} -d ${CONTAINER_ROOT_DIR}
docker exec -t ${CONTAINER_NAME} find ${CONTAINER_ROOT_DIR} -type d -exec chown ${FULL_USER} {} \;
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.name "${GIT_AUTHOR_NAME}"
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.email "${GIT_AUTHOR_EMAIL}"
else
BUILD_PARAMETERS="-quick"
fi
# Build
mkdir -p "${SUBSURFACE_ROOT}/${OUTPUT_DIR}"
docker exec -u ${FULL_USER} -e OUTPUT_DIR=${CONTAINER_SUBSURFACE_DIR}/${OUTPUT_DIR} -t ${CONTAINER_NAME} bash -x subsurface/packaging/android/qmake-build.sh ${BUILD_PARAMETERS}
# Stop the container
docker stop ${CONTAINER_NAME}

View file

@ -411,7 +411,7 @@ APK_DIR=$(dirname ${APK})
APK_FILE=$(basename ${APK}) APK_FILE=$(basename ${APK})
pushd ${APK_DIR} pushd ${APK_DIR}
if [ -n "${KEYSTORE_FILE+X}" -a -f "${KEYSTORE_FILE}" -a -n "${KEYSTORE_PASSWORD+X}" ]; then if [ -n "${KEYSTORE_FILE+X}" -a -f "${KEYSTORE_FILE-}" -a -n "${KEYSTORE_PASSWORD+X}" ]; then
APKSIGNER_PARAMS="" APKSIGNER_PARAMS=""
if [ -n "${KEYSTORE_ALIAS+X}" ]; then if [ -n "${KEYSTORE_ALIAS+X}" ]; then
APKSIGNER_PARAMS="${APKSIGNER_PARAMS} --ks-key-alias ${KEYSTORE_ALIAS}" APKSIGNER_PARAMS="${APKSIGNER_PARAMS} --ks-key-alias ${KEYSTORE_ALIAS}"

View file

@ -6,7 +6,7 @@ The preferred method to create a Windows installer is to use our own docker
image that has all the build components pre-assembled. image that has all the build components pre-assembled.
All it takes is this: All it takes is this:
``` ```.sh
export GIT_AUTHOR_NAME=<your name> export GIT_AUTHOR_NAME=<your name>
export GIT_AUTHOR_EMAIL=<email to be used with github> export GIT_AUTHOR_EMAIL=<email to be used with github>
@ -18,4 +18,4 @@ git submodule update
./packaging/windows/docker-build.sh ./packaging/windows/docker-build.sh
``` ```
This will result in subsurface-VERSION.exe and smtk2ssrf-VERSION.exe to be created in /some/path/subsurface/output/windows/. This will result in the two installers subsurface-VERSION.exe and smtk2ssrf-VERSION.exe to be created in /some/path/subsurface/output/windows/.

View file

@ -4,11 +4,12 @@
# Build the Subsurface Windows installer and the Smtk2ssrf Windows installer in a Docker container # Build the Subsurface Windows installer and the Smtk2ssrf Windows installer in a Docker container
# #
# Needs the following environment variables to be set croak() {
# GIT_AUTHOR_NAME=<your name> echo "$0: $*" >&2
# GIT_AUTHOR_EMAIL=<email to be used with github> exit 1
}
CONTAINER_NAME=windows-builder-docker CONTAINER_NAME=subsurface-windows-builder
pushd . pushd .
cd "$(dirname "$0")/../.." cd "$(dirname "$0")/../.."
@ -28,22 +29,23 @@ CONTAINER_ID=$(docker container ls -a -q -f name=${CONTAINER_NAME})
# Create the container if it does not exist # Create the container if it does not exist
if [[ -z "${CONTAINER_ID}" ]]; then if [[ -z "${CONTAINER_ID}" ]]; then
# We'll need these later
if [ -z ${GIT_AUTHOR_NAME+X} -o -z ${GIT_AUTHOR_EMAIL+X} ]; then
croak "Please make sure GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL are set for the first run of this script."
fi
docker create -v ${SUBSURFACE_ROOT}:${CONTAINER_SUBSURFACE_DIR} --name=${CONTAINER_NAME} subsurface/mxe-build:3.1.0 sleep infinity docker create -v ${SUBSURFACE_ROOT}:${CONTAINER_SUBSURFACE_DIR} --name=${CONTAINER_NAME} subsurface/mxe-build:3.1.0 sleep infinity
fi fi
# Start the container
docker start ${CONTAINER_NAME} docker start ${CONTAINER_NAME}
BUILD_PARAMETERS=""
if [[ -z "${CONTAINER_ID}" ]]; then if [[ -z "${CONTAINER_ID}" ]]; then
# Prepare the image for first use # Prepare the image for first use
docker exec -t ${CONTAINER_NAME} groupadd $(id -g -n) -o -g ${LOGIN_GROUP} docker exec -t ${CONTAINER_NAME} groupadd $(id -g -n) -o -g ${LOGIN_GROUP}
docker exec -t ${CONTAINER_NAME} useradd $(id -u -n) -o -u ${LOGIN_USER} -g ${LOGIN_GROUP} -d ${CONTAINER_ROOT_DIR} docker exec -t ${CONTAINER_NAME} useradd $(id -u -n) -o -u ${LOGIN_USER} -g ${LOGIN_GROUP} -d ${CONTAINER_ROOT_DIR}
docker exec -t ${CONTAINER_NAME} find ${CONTAINER_ROOT_DIR} -type d -exec chown ${FULL_USER} {} \; docker exec -t ${CONTAINER_NAME} find ${CONTAINER_ROOT_DIR} -type d -exec chown ${FULL_USER} {} \;
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global --add safe.directory ${CONTAINER_SUBSURFACE_DIR}
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global --add safe.directory ${CONTAINER_SUBSURFACE_DIR}/libdivecomputer
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global --add safe.directory ${CONTAINER_SUBSURFACE_DIR}/nightly-builds
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.name "${GIT_AUTHOR_NAME}" docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.name "${GIT_AUTHOR_NAME}"
docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.email "${GIT_AUTHOR_EMAIL}" docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.email "${GIT_AUTHOR_EMAIL}"