From 30c6e62e04fba5131f5b17512f77a4d6eae58d1d Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Wed, 28 Oct 2026 18:15:09 +0000 Subject: [PATCH 1/5] Update libs/oboe from 1.7.0 to 1.10.0 --- libs/oboe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/oboe b/libs/oboe index 8740d0fc32..a81bb9f87d 160000 --- a/libs/oboe +++ b/libs/oboe @@ -1 +1 @@ -Subproject commit 8740d0fc321a55489dbbf6067298201b7d2e106d +Subproject commit a81bb9f87d4105b84b682685d3bfbb5beca371d1 From c536266036d915a3303439c23ac73ee4bf1ad0f3 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Wed, 28 Oct 2026 18:16:02 +0000 Subject: [PATCH 2/5] Rewrite Android build --- .github/autobuild/android-dependencies_qt5.sh | 13 + .github/autobuild/android-output-paths.sh | 92 +++ .github/autobuild/android.sh | 545 +++++++++++++++--- .github/workflows/autobuild.yml | 16 +- .gitignore | 6 + COMPILING.md | 94 ++- Jamulus.pro | 18 +- android/AndroidManifest.xml | 3 +- tools/android-build.sh | 353 ++++++++++++ tools/android-build_qt5.settings.example | 22 + 10 files changed, 1074 insertions(+), 88 deletions(-) create mode 100644 .github/autobuild/android-dependencies_qt5.sh create mode 100644 .github/autobuild/android-output-paths.sh create mode 100755 tools/android-build.sh create mode 100644 tools/android-build_qt5.settings.example diff --git a/.github/autobuild/android-dependencies_qt5.sh b/.github/autobuild/android-dependencies_qt5.sh new file mode 100644 index 0000000000..007e10ad1d --- /dev/null +++ b/.github/autobuild/android-dependencies_qt5.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# The following version pinnings are semi-automatically checked for updates. +# Verify .github/workflows/bump-dependencies.yml when changing those manually: + +# Values are consumed by android.sh and the dependency cache key. +# shellcheck disable=SC2034 +COMMANDLINETOOLS_VERSION=6858069 +ANDROID_NDK_VERSION=r21d +ANDROID_PLATFORM=android-30 +ANDROID_BUILD_TOOLS=30.0.2 +AQTINSTALL_VERSION=3.3.0 +ANDROID_JAVA_VERSION=8 +QT_VERSION=5.15.2 diff --git a/.github/autobuild/android-output-paths.sh b/.github/autobuild/android-output-paths.sh new file mode 100644 index 0000000000..23fce5a4dd --- /dev/null +++ b/.github/autobuild/android-output-paths.sh @@ -0,0 +1,92 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2026 +# +# Author(s): +# Peter L Jones +# The Jamulus Development Team +# +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +# Sourced by android.sh and tools/android-build.sh. Requires PROJECT_DIR to be set. + +absolute_path() { + realpath -m -- "$1" +} + +BUILD_ROOT="$(absolute_path "${JAMULUS_ANDROID_BUILD_DIR:-${PROJECT_DIR}/android-build}")" +readonly BUILD_ROOT +DEPLOY_DIR="$(absolute_path "${JAMULUS_ANDROID_DEPLOY_DIR:-${PROJECT_DIR}/deploy}")" +readonly DEPLOY_DIR +readonly -a LEGACY_ANDROID_OUTPUTS=( + "${PROJECT_DIR}/debug" + "${PROJECT_DIR}/release" + "${PROJECT_DIR}/build" + "${PROJECT_DIR}/qmake_qmake_qm_files.qrc" + "${PROJECT_DIR}/.qm" +) + +path_is_within() { + local path="$1" + local root="$2" + [[ "$path" == "$root" || "$path" == "$root/"* ]] +} + +validate_android_output_paths() { + local generated_path + local output_path + local signing_path + local canonical_path + local -a output_paths=("$BUILD_ROOT" "$DEPLOY_DIR") + + for output_path in "${output_paths[@]}"; do + [[ "$output_path" != / && "$output_path" != "$PROJECT_DIR" && "$PROJECT_DIR" != "$output_path/"* ]] || { + echo "Refusing unsafe Android output path: $output_path" >&2 + exit 1 + } + for generated_path in "${LEGACY_ANDROID_OUTPUTS[@]}"; do + canonical_path="$(absolute_path "$generated_path")" || { + echo "Failed to resolve Android output path: $generated_path" >&2 + exit 1 + } + if path_is_within "$output_path" "$canonical_path"; then + echo "Android output path overlaps legacy generated output: $output_path" >&2 + exit 1 + fi + done + done + + if path_is_within "$BUILD_ROOT" "$DEPLOY_DIR" || path_is_within "$DEPLOY_DIR" "$BUILD_ROOT"; then + echo "Android build and deploy output paths must not overlap" >&2 + exit 1 + fi + + for signing_path in "${JAMULUS_ANDROID_KEYSTORE:-}" "${JAMULUS_ANDROID_DEBUG_KEYSTORE:-}"; do + [[ -n "$signing_path" ]] || continue + canonical_path="$(absolute_path "$signing_path")" || { + echo "Failed to resolve Android signing file path: $signing_path" >&2 + exit 1 + } + for output_path in "${output_paths[@]}" "${LEGACY_ANDROID_OUTPUTS[@]}"; do + if path_is_within "$canonical_path" "$output_path"; then + echo "Android signing file must not be inside a generated output path: $signing_path" >&2 + exit 1 + fi + done + done +} diff --git a/.github/autobuild/android.sh b/.github/autobuild/android.sh index 3b9ba1d841..fae6f4495a 100755 --- a/.github/autobuild/android.sh +++ b/.github/autobuild/android.sh @@ -48,110 +48,508 @@ set -eu -# Some of the following version pinnings are semi-automatically checked for -# updates. Update .github/workflows/bump-dependencies.yml when renaming those: -COMMANDLINETOOLS_VERSION=6858069 -ANDROID_NDK_VERSION=r21d -ANDROID_PLATFORM=android-30 -ANDROID_BUILD_TOOLS=30.0.2 -AQTINSTALL_VERSION=3.3.0 -QT_VERSION=5.15.2 +set -o pipefail + +if [[ ! ${JAMULUS_BUILD_VERSION:-} =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then + echo "Environment variable JAMULUS_BUILD_VERSION has to be set to a valid version string" + exit 1 +fi + +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +readonly PROJECT_DIR + +ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" +DEFAULT_ARTIFACT_SUFFIX="_qt5" + +# Save environment before sourcing the dependencies file, so we can restore overrides. +EXPLICIT_COMMANDLINETOOLS_VERSION="${COMMANDLINETOOLS_VERSION:-}" +EXPLICIT_ANDROID_NDK_VERSION="${ANDROID_NDK_VERSION:-}" +EXPLICIT_ANDROID_PLATFORM="${ANDROID_PLATFORM:-}" +EXPLICIT_ANDROID_BUILD_TOOLS="${ANDROID_BUILD_TOOLS:-}" +EXPLICIT_AQTINSTALL_VERSION="${AQTINSTALL_VERSION:-}" +EXPLICIT_ANDROID_JAVA_VERSION="${ANDROID_JAVA_VERSION:-}" +EXPLICIT_QT_VERSION="${QT_VERSION:-}" + +# shellcheck disable=SC1090 +source "$ANDROID_DEPENDENCIES" + +# Restore any explicit overrides from the environment, so they take precedence over the defaults in the dependencies file. +[[ -n "${EXPLICIT_COMMANDLINETOOLS_VERSION}" ]] && COMMANDLINETOOLS_VERSION="${EXPLICIT_COMMANDLINETOOLS_VERSION}" +[[ -n "${EXPLICIT_ANDROID_NDK_VERSION}" ]] && ANDROID_NDK_VERSION="${EXPLICIT_ANDROID_NDK_VERSION}" +[[ -n "${EXPLICIT_ANDROID_PLATFORM}" ]] && ANDROID_PLATFORM="${EXPLICIT_ANDROID_PLATFORM}" +[[ -n "${EXPLICIT_ANDROID_BUILD_TOOLS}" ]] && ANDROID_BUILD_TOOLS="${EXPLICIT_ANDROID_BUILD_TOOLS}" +[[ -n "${EXPLICIT_AQTINSTALL_VERSION}" ]] && AQTINSTALL_VERSION="${EXPLICIT_AQTINSTALL_VERSION}" +[[ -n "${EXPLICIT_ANDROID_JAVA_VERSION}" ]] && ANDROID_JAVA_VERSION="${EXPLICIT_ANDROID_JAVA_VERSION}" +[[ -n "${EXPLICIT_QT_VERSION}" ]] && QT_VERSION="${EXPLICIT_QT_VERSION}" + +# Defaults must match the cache values in .github/workflows/autobuild.yml +export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-${HOME}/android-sdk}" +export ANDROID_NDK_ROOT="${ANDROID_NDK_ROOT:-${HOME}/android-ndk}" +QT_DIR="${QT_DIR:-${HOME}/qt}" + +readonly TARGET_ARCHS="${TARGET_ARCHS:-armeabi-v7a arm64-v8a x86 x86_64}" + +# Ensure tools know where things are +export ANDROID_HOME="${ANDROID_SDK_ROOT}" +export ANDROID_NDK="${ANDROID_NDK_ROOT}" +export ANDROID_NDK_HOME="${ANDROID_NDK_ROOT}" +export ANDROID_NDK_LATEST_HOME="${ANDROID_NDK_ROOT}" +export ANDROID_SDK_BUILD_TOOLS_REVISION="${ANDROID_BUILD_TOOLS}" +export ANDROID_BUILD_TOOLS_REVISION="${ANDROID_BUILD_TOOLS}" + +if [[ ! ${QT_VERSION:-} =~ [0-9]+\.[0-9]+\..* ]]; then + echo "Environment variable QT_VERSION must be set to a valid Qt version" + exit 1 +fi + +[[ "${QT_VERSION}" =~ ^5\..* ]] || { + echo "The Qt 5 Android build requires Qt 5; received ${QT_VERSION}" >&2 + exit 1 +} +QT_ANDROID_DIR="${QT_DIR}/${QT_VERSION}/android" +QT_ANDROIDDEPLOYQT="${QT_ANDROID_DIR}/bin/androiddeployqt" +readonly QT_ANDROID_DIR +readonly QT_ANDROIDDEPLOYQT + +export QT_SELECT +QT_SELECT="${QT_VERSION}-$(basename "${QT_ANDROID_DIR}")" +export QTTOOLDIR="${QT_ANDROID_DIR}/bin" +export QTLIBDIR="${QT_ANDROID_DIR}/lib" # Only variables which are really needed by sub-commands are exported. # Definitions have to stay in a specific order due to dependencies. -QT_BASEDIR="/opt/Qt" -ANDROID_BASEDIR="/opt/android" -BUILD_DIR=build -export ANDROID_SDK_ROOT="${ANDROID_BASEDIR}/android-sdk" -COMMANDLINETOOLS_DIR="${ANDROID_SDK_ROOT}"/cmdline-tools/latest/ -export ANDROID_NDK_ROOT="${ANDROID_BASEDIR}/android-ndk" -ANDROID_NDK_HOST="linux-x86_64" -ANDROID_SDKMANAGER="${COMMANDLINETOOLS_DIR}/bin/sdkmanager" -export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/" -export PATH="${PATH}:${ANDROID_SDK_ROOT}/tools" -export PATH="${PATH}:${ANDROID_SDK_ROOT}/platform-tools" +export PATH="${ANDROID_SDK_ROOT}/tools:${PATH}" +export PATH="${ANDROID_SDK_ROOT}/platform-tools:${PATH}" +export JAVA_HOME="${JAVA_HOME:-/usr/lib/jvm/java-${ANDROID_JAVA_VERSION:-8}-openjdk-amd64/}" -if [[ ! ${JAMULUS_BUILD_VERSION:-} =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then - echo "Environment variable JAMULUS_BUILD_VERSION has to be set to a valid version string" +for var in ANDROID_BUILD_TOOLS_REVISION ANDROID_HOME ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT ANDROID_SDK_BUILD_TOOLS_REVISION ANDROID_SDK_ROOT DEBIAN_FRONTEND JAMULUS_BUILD_VERSION JAVA_HOME PATH QTLIBDIR QT_SELECT QTTOOLDIR; do + if [[ -n "${!var:-}" ]]; then echo $var=${!var}; fi +done +for var in JAMULUS_ANDROID_KEY_ALIAS JAMULUS_ANDROID_KEY_PASSWORD JAMULUS_ANDROID_KEYSTORE JAMULUS_ANDROID_KEYSTORE_BASE64 JAMULUS_ANDROID_KEYSTORE_PASSWORD; do + if [[ -n "${!var:-}" ]]; then echo $var='****'; fi +done + +readonly QT_QMAKE="${QT_ANDROID_DIR}/bin/qmake" + +# shellcheck disable=SC1090 +source "${PROJECT_DIR}/.github/autobuild/android-output-paths.sh" + +readonly BUILD_MODES="${BUILD_MODES:-debug release}" +readonly QMAKE_CONFIG="${JAMULUS_ANDROID_QMAKE_CONFIG:-}" +MAX_MAKE_JOBS="$(nproc)" +readonly MAX_MAKE_JOBS +readonly MAKE_JOBS="${JAMULUS_ANDROID_MAKE_JOBS:-${MAX_MAKE_JOBS}}" +readonly ARTIFACT_SUFFIX="${JAMULUS_ANDROID_ARTIFACT_SUFFIX:-${DEFAULT_ARTIFACT_SUFFIX}}" + +if [[ ! "$MAKE_JOBS" =~ ^[1-9][0-9]*$ ]] || ((MAKE_JOBS > MAX_MAKE_JOBS)); then + echo "JAMULUS_ANDROID_MAKE_JOBS must be a positive integer no greater than ${MAX_MAKE_JOBS}" >&2 exit 1 fi +readonly JAMULUS_ANDROID_KEYSTORE="${JAMULUS_ANDROID_KEYSTORE:-}" +readonly JAMULUS_ANDROID_KEYSTORE_BASE64="${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" +JAMULUS_ANDROID_KEY_ALIAS="${JAMULUS_ANDROID_KEY_ALIAS:-}" +JAMULUS_ANDROID_KEYSTORE_PASSWORD="${JAMULUS_ANDROID_KEYSTORE_PASSWORD:-}" +JAMULUS_ANDROID_KEY_PASSWORD="${JAMULUS_ANDROID_KEY_PASSWORD:-}" + +readonly COMMANDLINETOOLS_DIR="${ANDROID_SDK_ROOT}"/cmdline-tools/latest +readonly ANDROID_SDKMANAGER=("${COMMANDLINETOOLS_DIR}/bin/sdkmanager" "--sdk_root=${ANDROID_SDK_ROOT}") + +readonly ANDROID_NDK_HOST="${ANDROID_NDK_HOST:-linux-x86_64}" +readonly ANDROID_NDK_MAKE=${ANDROID_NDK_ROOT}/prebuilt/${ANDROID_NDK_HOST}/bin/make + setup_ubuntu_dependencies() { export DEBIAN_FRONTEND="noninteractive" sudo apt-get -qq update - sudo apt-get -qq --no-install-recommends -y install build-essential zip unzip bzip2 p7zip-full curl chrpath openjdk-8-jdk-headless + sudo apt-get -qq --no-install-recommends -y install build-essential zip unzip bzip2 p7zip-full curl chrpath "openjdk-${ANDROID_JAVA_VERSION:-8}-jdk-headless" } setup_android_sdk() { - mkdir -p "${ANDROID_BASEDIR}" + # We may need to create the cmdline_tools directory and chown it to the runner user to fix permissions + # (even after cache recovery) + sudo mkdir -p "${COMMANDLINETOOLS_DIR}" + sudo chown -R "$(whoami)" "${ANDROID_SDK_ROOT}" - if [[ -d "${COMMANDLINETOOLS_DIR}" ]]; then - echo "Using commandlinetools installation from previous run (actions/cache)" - else - mkdir -p "${COMMANDLINETOOLS_DIR}" - curl -s -o downloadfile "https://dl.google.com/android/repository/commandlinetools-linux-${COMMANDLINETOOLS_VERSION}_latest.zip" - unzip -q downloadfile - mv cmdline-tools/* "${COMMANDLINETOOLS_DIR}" + # sdkmanager doesn't record which cmdline-tools build we downloaded, so track that + # ourselves; platforms/build-tools are already installed under a directory named + # after the exact requested version, so no extra marker is needed for those. + local cmdlinetools_version_marker="${COMMANDLINETOOLS_DIR}/.jamulus-cmdlinetools-version" + + if [[ -d "${COMMANDLINETOOLS_DIR}" && -x "${ANDROID_SDKMANAGER[0]}" && + -f "$cmdlinetools_version_marker" && + "$(cat "$cmdlinetools_version_marker")" == "${COMMANDLINETOOLS_VERSION}" && + -d "${ANDROID_SDK_ROOT}/platforms/${ANDROID_PLATFORM}" && + -d "${ANDROID_SDK_ROOT}/build-tools/${ANDROID_BUILD_TOOLS}" ]]; then + echo "Using SDK installation (cmdline-tools: ${COMMANDLINETOOLS_VERSION}, platforms: ${ANDROID_PLATFORM}, build-tools: ${ANDROID_BUILD_TOOLS}) from previous run (actions/cache)" + return fi - yes | "${ANDROID_SDKMANAGER}" --licenses - "${ANDROID_SDKMANAGER}" --update - "${ANDROID_SDKMANAGER}" "platforms;${ANDROID_PLATFORM}" - "${ANDROID_SDKMANAGER}" "build-tools;${ANDROID_BUILD_TOOLS}" + echo "Installing SDK (cmdline-tools: ${COMMANDLINETOOLS_VERSION}, platforms: ${ANDROID_PLATFORM}, build-tools: ${ANDROID_BUILD_TOOLS})" + # Clear any mismatched-version leftovers so files from different cmdline-tools builds can't mix. + find "${COMMANDLINETOOLS_DIR:?}" -mindepth 1 -delete + pushd "${COMMANDLINETOOLS_DIR}" > /dev/null + + curl -s -o downloadfile.zip "https://dl.google.com/android/repository/commandlinetools-linux-${COMMANDLINETOOLS_VERSION}_latest.zip" + unzip -q downloadfile.zip -d sdk-tmpdir + rm -f downloadfile.zip + + mv sdk-tmpdir/cmdline-tools/* . + rm -rf sdk-tmpdir + + popd > /dev/null + echo "${COMMANDLINETOOLS_VERSION}" > "$cmdlinetools_version_marker" + + set +o pipefail + yes | "${ANDROID_SDKMANAGER[@]}" --licenses + "${ANDROID_SDKMANAGER[@]}" --update + yes | "${ANDROID_SDKMANAGER[@]}" "platforms;${ANDROID_PLATFORM}" + yes | "${ANDROID_SDKMANAGER[@]}" "build-tools;${ANDROID_BUILD_TOOLS}" + yes | "${ANDROID_SDKMANAGER[@]}" --licenses + echo ===================== + echo "Android SDK licenses under ${ANDROID_SDK_ROOT}:" + find "${ANDROID_SDK_ROOT}" -type d -name licenses -prune -exec ls -ltrR '{}' \; + echo ===================== + set -o pipefail } setup_android_ndk() { - mkdir -p "${ANDROID_BASEDIR}" - if [[ -d "${ANDROID_NDK_ROOT}" ]]; then - echo "Using NDK installation from previous run (actions/cache)" + # We may need to create the NDK installation directory and chown it to the runner user to fix permissions + # (even after cache recovery) + sudo mkdir -p "${ANDROID_NDK_ROOT}" + sudo chown -R "$(whoami)" "${ANDROID_NDK_ROOT}" + + # The NDK is unpacked flat into ANDROID_NDK_ROOT, so its directory layout + # doesn't encode the version; track it ourselves to validate cache hits. + local ndk_version_marker="${ANDROID_NDK_ROOT}/.jamulus-ndk-version" + + if [[ -f "${ANDROID_NDK_ROOT}/source.properties" && -x "${ANDROID_NDK_MAKE}" && + -f "$ndk_version_marker" && "$(cat "$ndk_version_marker")" == "${ANDROID_NDK_VERSION}" ]]; then + echo "Using NDK ${ANDROID_NDK_VERSION} installation from previous run (actions/cache)" + return + fi + + echo "Installing NDK ${ANDROID_NDK_VERSION}" + # Remove any mismatched-version leftovers so files from different NDK releases can't mix. + find "${ANDROID_NDK_ROOT:?}" -mindepth 1 -delete + pushd "${ANDROID_NDK_ROOT}" > /dev/null + + # Ugh... Should be optimised... + if [[ "${ANDROID_NDK_VERSION}" == "$( + { + echo "r22b" + echo "${ANDROID_NDK_VERSION}" + } | sort | head -1 + )" ]]; then + suffix="-x86_64" else - curl -s -o downloadfile "https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip" - unzip -q downloadfile - mv "android-ndk-${ANDROID_NDK_VERSION}" "${ANDROID_NDK_ROOT}" + suffix="" fi + curl -s -o downloadfile.zip "https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux${suffix}.zip" + unzip -q downloadfile.zip -d ndk-tmpdir + rm -f downloadfile.zip + + mv ndk-tmpdir/"android-ndk-${ANDROID_NDK_VERSION}"/* . + rm -rf ndk-tmpdir + + popd > /dev/null + echo "${ANDROID_NDK_VERSION}" > "$ndk_version_marker" } setup_qt() { - if [[ -d "${QT_BASEDIR}" ]]; then - echo "Using Qt installation from previous run (actions/cache)" + # We may need to create the Qt installation directory and chown it to the runner user to fix permissions + # (even after cache recovery) + sudo mkdir -p "${QT_DIR}" + sudo chown -R "$(whoami)" "${QT_DIR}" + + # QT_QMAKE and QT_ANDROIDDEPLOYQT are under a version-named directory. + if [[ -x "${QT_QMAKE}" && -x "${QT_ANDROIDDEPLOYQT}" ]]; then + echo "Using Qt ${QT_VERSION} installation from previous run (actions/cache)" + return + fi + + echo "Installing Qt" + # Remove any mismatched-version leftovers so files from different NDK releases can't mix. + sudo mkdir -p "${QT_DIR}/${QT_VERSION}" + sudo chown -R "$(whoami)" "${QT_DIR}/${QT_VERSION}" + find "${QT_DIR:?}/${QT_VERSION}" -mindepth 1 -delete + + # Create and enter virtual environment + python3 -m venv venv + # Must hide directory as it just gets created during execution of the previous command and cannot be found by shellcheck + # shellcheck source=/dev/null + source venv/bin/activate + + pip install "aqtinstall==${AQTINSTALL_VERSION}" + + # Install actual Android Qt: + local qt_archives=(qtbase qttools qttranslations qtandroidextras qtmultimedia) + python3 -m aqt install-qt --outputdir "${QT_DIR}" linux android "${QT_VERSION}" \ + --archives "${qt_archives[@]}" + + # Delete libraries, which we don't use, but which bloat the resulting package and might introduce unwanted dependencies. + # iOS does not do this - leave for now, fix across all later. + find "$QT_ANDROID_DIR" -name 'libQt*Quick*.so' -delete + rm -rf "$QT_ANDROID_DIR/qml/" + + # deactivate and remove venv as aqt is no longer needed from here on + deactivate + rm -rf venv +} + +validate_build_mode() { + local build_mode + + [[ -n "$BUILD_MODES" ]] || { + echo "BUILD_MODES must select debug and/or release" >&2 + exit 1 + } + for build_mode in $BUILD_MODES; do + [[ "$build_mode" == debug || "$build_mode" == release ]] || { + echo "Unsupported Android build mode: $build_mode" >&2 + exit 1 + } + done +} + +validate_android_toolchain() { + [[ -f "${ANDROID_NDK_ROOT}/source.properties" ]] || { + echo "Selected Android NDK is not installed: ${ANDROID_NDK_ROOT}" >&2 + echo "Run '$0 setup' or set ANDROID_NDK_ROOT to an installed NDK." >&2 + exit 1 + } + [[ -d "${ANDROID_SDK_ROOT}/platforms/${ANDROID_PLATFORM}" ]] || { + echo "Selected Android platform is not installed: ${ANDROID_SDK_ROOT}/platforms/${ANDROID_PLATFORM}" >&2 + echo "Run '$0 setup' or install ${ANDROID_PLATFORM} with sdkmanager." >&2 + exit 1 + } + [[ -x "${ANDROID_SDK_ROOT}/build-tools/${ANDROID_BUILD_TOOLS}/aapt" ]] || { + echo "Selected Android build tools are not installed: ${ANDROID_SDK_ROOT}/build-tools/${ANDROID_BUILD_TOOLS}" >&2 + echo "Run '$0 setup' or install build-tools;${ANDROID_BUILD_TOOLS} with sdkmanager." >&2 + exit 1 + } +} + +validate_signing() { + local signing_setting + [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}" ]] && echo "No Android keystore file specified" >&2 + [[ -z "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] && echo "No Android keystore base64 specified" >&2 + [[ -z "${JAMULUS_ANDROID_KEY_ALIAS:-}" ]] && echo "No Android keystore alias specified" >&2 + [[ -z "${JAMULUS_ANDROID_KEYSTORE_PASSWORD:-}" ]] && echo "No Android keystore password specified" >&2 + [[ -z "${JAMULUS_ANDROID_KEY_PASSWORD:-}" ]] && echo "No Android key password specified" >&2 + + [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}" || -z "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] || { + echo "Set only one of JAMULUS_ANDROID_KEYSTORE and JAMULUS_ANDROID_KEYSTORE_BASE64" >&2 + exit 1 + } + for signing_setting in JAMULUS_ANDROID_KEYSTORE JAMULUS_ANDROID_KEYSTORE_BASE64 \ + JAMULUS_ANDROID_KEY_ALIAS \ + JAMULUS_ANDROID_KEYSTORE_PASSWORD JAMULUS_ANDROID_KEY_PASSWORD; do + [[ -z "${!signing_setting:-}" || -n "${JAMULUS_ANDROID_KEYSTORE:-}" || + -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] || { + echo "$signing_setting requires an Android keystore" >&2 + exit 1 + } + done + if [[ -n "${JAMULUS_ANDROID_KEYSTORE:-}" || -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then + [[ -n "${JAMULUS_ANDROID_KEY_ALIAS:-}" ]] || { + echo "JAMULUS_ANDROID_KEY_ALIAS is required with a keystore" >&2 + exit 1 + } + [[ -n "${JAMULUS_ANDROID_KEYSTORE_PASSWORD:-}" ]] || { + echo "JAMULUS_ANDROID_KEYSTORE_PASSWORD is required with a keystore" >&2 + exit 1 + } + fi + validate_android_output_paths + + if [[ -n "${JAMULUS_ANDROID_KEYSTORE:-}" || -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then + prepare_keystore + elif [[ " $BUILD_MODES " == *" release "* ]]; then + prepare_debug_keystore + fi +} + +prepare_keystore() { + if [[ -n "${JAMULUS_ANDROID_KEYSTORE:-}" ]]; then + [[ -r "$JAMULUS_ANDROID_KEYSTORE" ]] || { + echo "Android keystore is not readable: $JAMULUS_ANDROID_KEYSTORE" >&2 + exit 1 + } + ANDROID_KEYSTORE_FILE="$(absolute_path "$JAMULUS_ANDROID_KEYSTORE")" + return + fi + + if [[ -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then + if ! ANDROID_KEYSTORE_FILE="$(mktemp "${TMPDIR:-/tmp}/jamulus-android-signing.XXXXXX")"; then + echo "Failed to create temporary Android keystore file" >&2 + exit 1 + fi + trap 'rm -f -- "$ANDROID_KEYSTORE_FILE"' EXIT + chmod 600 "$ANDROID_KEYSTORE_FILE" + printf '%s' "$JAMULUS_ANDROID_KEYSTORE_BASE64" | base64 --decode > "$ANDROID_KEYSTORE_FILE" + fi +} + +prepare_debug_keystore() { + local debug_keystore="${JAMULUS_ANDROID_DEBUG_KEYSTORE:-}" + + JAMULUS_ANDROID_KEYSTORE_PASSWORD="android" + JAMULUS_ANDROID_KEY_ALIAS="androiddebugkey" + JAMULUS_ANDROID_KEY_PASSWORD="android" + + if [[ -n "$debug_keystore" ]]; then + ANDROID_KEYSTORE_FILE="$(absolute_path "$debug_keystore")" + if [[ -e "$ANDROID_KEYSTORE_FILE" || -L "$ANDROID_KEYSTORE_FILE" ]]; then + if [[ -f "$ANDROID_KEYSTORE_FILE" && -r "$ANDROID_KEYSTORE_FILE" ]] && + keytool -list -keystore "$ANDROID_KEYSTORE_FILE" \ + -storepass "$JAMULUS_ANDROID_KEYSTORE_PASSWORD" \ + -alias "$JAMULUS_ANDROID_KEY_ALIAS" > /dev/null 2>&1; then + return + else + echo "Invalid Android debug keystore: $ANDROID_KEYSTORE_FILE" >&2 + exit 1 + fi + fi else - echo "Installing Qt..." - python3 -m pip install "aqtinstall==${AQTINSTALL_VERSION}" - local qtmultimedia=() - if [[ ! "${QT_VERSION}" =~ 5\..* ]]; then - # From Qt6 onwards, qtmultimedia is a module and cannot be installed - # as an archive anymore. - qtmultimedia=("--modules") + if ! ANDROID_KEYSTORE_TEMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/jamulus-android-debug-signing.XXXXXX")"; then + echo "Failed to create temporary Android debug keystore" >&2 + exit 1 fi - qtmultimedia+=("qtmultimedia") - - python3 -m aqt install-qt --outputdir "${QT_BASEDIR}" linux android "${QT_VERSION}" \ - --archives qtbase qttools qttranslations qtandroidextras \ - "${qtmultimedia[@]}" - # Delete libraries, which we don't use, but which bloat the resulting package and might introduce unwanted dependencies. - find "${QT_BASEDIR}" -name 'libQt5*Quick*.so' -delete - rm -r "${QT_BASEDIR}/${QT_VERSION}/android/qml/" + ANDROID_KEYSTORE_FILE="${ANDROID_KEYSTORE_TEMP_DIR}/debug.jks" + trap 'rm -rf -- "$ANDROID_KEYSTORE_TEMP_DIR"' EXIT fi + + mkdir -p "$(dirname "$ANDROID_KEYSTORE_FILE")" + keytool -genkeypair \ + -keystore "$ANDROID_KEYSTORE_FILE" \ + -storepass "$JAMULUS_ANDROID_KEYSTORE_PASSWORD" \ + -alias "$JAMULUS_ANDROID_KEY_ALIAS" \ + -keypass "$JAMULUS_ANDROID_KEY_PASSWORD" \ + -keyalg RSA \ + -keysize 2048 \ + -validity 10000 \ + -dname "CN=Android Debug,O=Android,C=US" + chmod 600 "$ANDROID_KEYSTORE_FILE" } -build_app_as_apk() { - local QT_DIR="${QT_BASEDIR}/${QT_VERSION}/android" - local MAKE="${ANDROID_NDK_ROOT}/prebuilt/${ANDROID_NDK_HOST}/bin/make" +keystore_type() { + local keystore_file="$1" + local storepass="${2:-}" + local detected_type - "${QT_DIR}/bin/qmake" -spec android-clang - "${MAKE}" -j "$(nproc)" - "${MAKE}" INSTALL_ROOT="${BUILD_DIR}" -f Makefile install - "${QT_DIR}"/bin/androiddeployqt --input android-Jamulus-deployment-settings.json --output "${BUILD_DIR}" \ - --android-platform "${ANDROID_PLATFORM}" --jdk "${JAVA_HOME}" --gradle + if [[ -z "$storepass" ]]; then + detected_type="$(keytool -list -keystore "$keystore_file" 2> /dev/null | awk 'BEGIN{IGNORECASE=1; status=1} /^Keystore type:/ {print $3; status=0} END {exit status}')" + else + detected_type="$(keytool -list -keystore "$keystore_file" -storepass "$storepass" 2> /dev/null | awk 'BEGIN{IGNORECASE=1; status=1} /^Keystore type:/ {print $3; status=0} END {exit status}')" + fi + + [[ -n "$detected_type" ]] || return 1 + printf '%s' "$detected_type" +} + +qmake5_qmake_make() { + local build_mode="$1" + shift + local build_dir="$1" + shift + local -n _p="$1" + shift + local qmake_config=("$@") + local -a package_args=("${_p[@]}") + + build_dir="$(absolute_path "$build_dir")" + pushd "${build_dir}" > /dev/null + "${QT_QMAKE}" "${PROJECT_DIR}/Jamulus.pro" -spec android-clang "${qmake_config[@]}" \ + ANDROID_ABIS="${TARGET_ARCHS}" ANDROID_TARGET_SDK_VERSION=30 + + "${ANDROID_NDK_MAKE}" -j "$MAKE_JOBS" + "${ANDROID_NDK_MAKE}" INSTALL_ROOT="${build_dir}" install + + if [[ "$build_mode" == release && -n "${ANDROID_KEYSTORE_FILE:-}" ]]; then + package_args+=(--sign "${ANDROID_KEYSTORE_FILE}" "${JAMULUS_ANDROID_KEY_ALIAS}" --storepass "${JAMULUS_ANDROID_KEYSTORE_PASSWORD}") + [[ -n "${JAMULUS_ANDROID_KEY_PASSWORD:-}" ]] && package_args+=(--keypass "${JAMULUS_ANDROID_KEY_PASSWORD}") + fi + "${QT_ANDROIDDEPLOYQT}" --verbose --input android-Jamulus-deployment-settings.json --output "${build_dir}" "${package_args[@]}" + popd > /dev/null +} + +build_app() { + local build_mode="$1" + local build_dir="${BUILD_ROOT}/${build_mode}" + local qmake_config=() + + for config in $QMAKE_CONFIG; do + qmake_config+=("CONFIG+=${config}") + done + qmake_config+=("CONFIG+=android_single_config" "CONFIG+=${build_mode}" "CONFIG-=debug_and_release") + echo "qmake config: ${qmake_config[*]}; android ABIs: ${TARGET_ARCHS}" + + local package_args=() + package_args+=(--android-platform "${ANDROID_PLATFORM}" --jdk "${JAVA_HOME}") + if [[ "$build_mode" == release ]]; then + package_args+=(--release) + if [[ -n "${ANDROID_KEYSTORE_FILE:-}" ]]; then + local detected_keystore_type + detected_keystore_type="$(keystore_type "${ANDROID_KEYSTORE_FILE}" "${JAMULUS_ANDROID_KEYSTORE_PASSWORD}")" || detected_keystore_type="unknown" + + if [[ "$detected_keystore_type" == "PKCS12" ]]; then + package_args+=(--storetype PKCS12) + echo "Android release signing: forcing --storetype PKCS12 for PKCS12 keystore" + else + echo "Android release signing: leaving keystore type unspecified for ${detected_keystore_type} keystore" + fi + fi + fi + + echo "Android packaging: format=APK platform=${ANDROID_PLATFORM}" + + # Diagnostic environment - non-secret variables only + echo "Android environment:" + for var in ANDROID_PLATFORM ANDROID_SDK_ROOT ANDROID_NDK_ROOT TARGET_ARCHS JAVA_HOME QT_HOST_PATH ANDROID_BUILD_TOOLS; do + [[ -n "${!var:-}" ]] && echo " ${var}=${!var}" + done + + rm -rf "${build_dir}" + mkdir -p "${build_dir}" + + qmake5_qmake_make "$build_mode" "${build_dir}" package_args "${qmake_config[@]}" } pass_artifact_to_job() { - mkdir deploy - local artifact="jamulus_${JAMULUS_BUILD_VERSION}_android.apk" - echo "Moving ${BUILD_DIR}/build/outputs/apk/debug/build-debug.apk to deploy/${artifact}" - mv "./${BUILD_DIR}/build/outputs/apk/debug/build-debug.apk" "./deploy/${artifact}" - echo "artifact_1=${artifact}" >> "$GITHUB_OUTPUT" + if [[ -z "${JAMULUS_BUILD_VERSION:-}" ]]; then + JAMULUS_BUILD_VERSION="$(python3 "${PROJECT_DIR}/.github/autobuild/get_build_vars.py" --print-build-version)" + export JAMULUS_BUILD_VERSION + fi + [[ ${JAMULUS_BUILD_VERSION:-} =~ [0-9]+\.[0-9]+\.[0-9]+ ]] || { + echo "JAMULUS_BUILD_VERSION has to be a valid version string" >&2 + exit 1 + } + mkdir -p "${DEPLOY_DIR}" + local artifact_number=1 + local build_mode + local artifact + local package_path + + for build_mode in $BUILD_MODES; do + artifact="jamulus_${JAMULUS_BUILD_VERSION}_android_${build_mode}${ARTIFACT_SUFFIX}.apk" + if [[ "$build_mode" == debug ]]; then + package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-debug.apk' -print -quit)" + else + package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-signed.apk' -print -quit)" + fi + [[ -n "$package_path" ]] || { + echo "No Android APK was produced for ${build_mode}" >&2 + exit 1 + } + mv "$package_path" "${DEPLOY_DIR}/${artifact}" + if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "artifact_${artifact_number}=${artifact}" >> "$GITHUB_OUTPUT" + else + echo "${DEPLOY_DIR}/${artifact}" + fi + artifact_number=$((artifact_number + 1)) + done } case "${1:-}" in @@ -162,7 +560,12 @@ case "${1:-}" in setup_qt ;; build) - build_app_as_apk + validate_build_mode + validate_android_toolchain + validate_signing + for build_mode in $BUILD_MODES; do + build_app "$build_mode" + done ;; get-artifacts) pass_artifact_to_job diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index b2fa3f5de5..26940a3db3 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -195,12 +195,14 @@ jobs: # Think of this like a foreach loop. Basically runs the steps with every combination of # the contents of this. config: - - config_name: Android .apk (artifact+codeQL) + - config_name: Android Qt5 .apk (artifact+codeQL) target_os: android building_on_os: ubuntu-22.04 - base_command: ./.github/autobuild/android.sh + # override runner environment variables to avoid picking up any pre-installed Android SDK/NDK/Qt versions + base_command: JAVA_HOME= QT_DIR= ANDROID_NDK_ROOT= ANDROID_SDK_ROOT= JAMULUS_ANDROID_STREAM=qt5 ./.github/autobuild/android.sh run_codeql: true is_main_build_target: true + dependency_cache_key: qt5 # Jamulus.pro needs to count git history length for android versioning: checkout_fetch_depth: '0' @@ -336,14 +338,14 @@ jobs: key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/autobuild/windows-dependencies.ps1') }}-${{ matrix.config.dependency_cache_key }} - name: Cache Android dependencies - if: matrix.config.target_os == 'android' + if: matrix.config.target_os == 'android' && matrix.config.dependency_cache_key == 'qt5' uses: actions/cache@v6 with: path: | - /opt/Qt - /opt/android/android-sdk - /opt/android/android-ndk - key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/workflows/autobuild.yml', '.github/autobuild/android.sh') }}-${{ matrix.config.base_command }} + ~/qt + ~/android-sdk + ~/android-ndk + key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/autobuild/android-dependencies_qt5.sh') }}-${{ matrix.config.dependency_cache_key }} - name: Set up build dependencies for ${{ matrix.config.config_name }} run: ${{ matrix.config.base_command }} setup diff --git a/.gitignore b/.gitignore index 5fdaa6d3dc..3689f782ab 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,8 @@ build/ deploy/ build-gui/ build-nox/ +android-build/ +android-Jamulus-deployment-settings.json jamulus.sln jamulus.vcxproj jamulus.vcxproj.filters @@ -58,3 +60,7 @@ jamulus_plugin_import.cpp .github_release_changelog.md /debian/ .github/instructions/awesome-copilot-instructions +*.jks +**/*.log +android-build_*.settings +Copilot-Processing.md diff --git a/COMPILING.md b/COMPILING.md index b82dcab9cf..d4abdb105d 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -6,7 +6,7 @@ - For unattended installs, see the contributed [installation scripts](https://github.com/jamulussoftware/installscripts) - The [Autobuild scripts](https://github.com/jamulussoftware/jamulus/tree/main/.github/autobuild) although only optimized to be used by the CI, might help you understand the process of setting up a build environment - There are reports from people who successfully compile and run Jamulus on BSDs. -- Android and iOS are not officially supported fully. However, [binaries are generated by the autobuild process](https://github.com/jamulussoftware/jamulus/releases/latest) in the Jamulus repository. +- Android and iOS are not officially supported fully. However, [binaries are generated by the autobuild process](https://github.com/jamulussoftware/jamulus/releases/latest) in the Jamulus repository. For Android, [tools/android-build.sh](tools/android-build.sh) can be used on Linux and this is explained further below. --- @@ -192,12 +192,92 @@ If you want to build the installer, please run the `deploy_mac.sh` script: `./ma ## Android -- Install Qt, including the Android support from the Qt installer -- Follow Qt's [Getting Started with Qt for Android](https://doc.qt.io/qt-5/android-getting-started.html) instructions -- **Important**: Make sure Jamulus submodules are present, notably oboe: - `git submodule update --init` -- Open Jamulus.pro in Qt Creator -- Now you should be able to Build & Run for Android. +Jamulus's Android side-load build uses Qt 5 and produces an APK: + +| Qt | Package | Java | NDK | Build Tools | Compile platform / target SDK | +| -- | ------- | ---- | --- | ----------- | ----------------------------- | +| 5.15.2 | APK | 8 | r21d (21.0.6113669) | 30.0.2 | Android 11 / API 30 | + +The APK supports devices from Android 5.0/API 21. + +- Install Qt 5.15.2 with `qtbase`, `qttools`, `qttranslations`, + `qtandroidextras`, and `qtmultimedia`, plus JDK 8, Android NDK r21d, + Android SDK Platform 30, and Build Tools 30.0.2. The GitHub workflow installs + these dependencies on its runner; local builds use the installed toolchain. + +As of Jamulus 4.0.0, the Android package ID is `app.jamulus.jamulus`. +Prior installation using the former `com.github.jamulussoftware.jamulus` ID will not be upgraded in-place. +(Users must uninstall the former package before installing the new one, losing their settings). +- Make sure the Jamulus submodules are present, notably oboe: + `git submodule update --init --recursive` + +### Local builds + +Use `tools/android-build.sh` for local builds. It selects the toolchain for the +Qt 5 profile, loads optional machine-specific overrides, sets +`JAMULUS_BUILD_VERSION` from `Jamulus.pro` (and the git hash for development +versions), and passes the same environment to every `android.sh` stage. + +Create an ignored settings file for local toolchain overrides: + +```bash +cp tools/android-build_qt5.settings.example android-build_qt5.settings +``` + +The Qt 5 wrapper loads `android-build_qt5.settings` by default. Set +machine-specific toolchain paths and ABI/mode subsets there. Inspect the +resolved environment with `--print-env`. + +Build Qt 5 APKs, which are suitable for temporary or release side-loading: + +```bash +tools/android-build.sh --stream qt5 --log android-qt5.log +``` + +### Build options + +- The Android driver defaults to all four ABIs and both debug and release modes. + Build outputs are written below + `android-build/debug/` and `android-build/release/`; running `get-artifacts` + moves them to `deploy/`. Artifacts use the `_qt5` suffix. +- Remove all generated Android build and deployment outputs with: + + ```bash + tools/android-build.sh distclean + ``` + + This removes `android-build/`, `deploy/`, and the known legacy qmake Android + output paths, but leaves similarly named files and unrelated untracked + files in the checkout alone. +- To build only the release compilation variant, set `BUILD_MODES=release`. + Select a subset of architectures with `TARGET_ARCHS`: + + ```bash + BUILD_MODES=release \ + TARGET_ARCHS="arm64-v8a x86_64" \ + tools/android-build.sh build get-artifacts + ``` + + Add qmake configuration values with `JAMULUS_ANDROID_QMAKE_CONFIG`: + + ```bash + JAMULUS_ANDROID_QMAKE_CONFIG="serveronly disable_version_check" \ + .github/autobuild/android.sh build + ``` + + Set `ANDROID_NDK_ROOT` or `QT_DIR` to use different installed toolchains. + Set `ANDROID_PLATFORM` to select the Android SDK platform. +- Debug builds are packaged as debuggable APKs. Local release builds use a + temporary debug keystore by default; it is deleted after the build. Set + `JAMULUS_ANDROID_DEBUG_KEYSTORE` to retain and reuse a debug keystore. An + existing file must be a valid Android debug keystore; a missing file is + created and retained. This key is for local development only, not for + publishing releases. +- Release builds use the normal positive Git revision count as their Android + version code for non-development versions. Development builds default to + version code `1`. Set `JAMULUS_ANDROID_VERSION_CODE` when a build needs an + explicit positive version code. +- An APK can be installed directly with `adb`. ## Compile time arguments diff --git a/Jamulus.pro b/Jamulus.pro index 1fcef0fdf3..299688f269 100644 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -250,11 +250,26 @@ win32 { LIBS += -framework AVFoundation \ -framework AudioToolbox } else:android { + CONFIG -= debug_and_release isEmpty(ANDROID_ABIS) { ANDROID_ABIS = armeabi-v7a arm64-v8a x86 x86_64 } ANDROID_VERSION_NAME = $$VERSION - ANDROID_VERSION_CODE = $$system(git log --oneline | wc -l) + ANDROID_VERSION_CODE = 1 + + JAMULUS_ANDROID_VERSION_CODE = $$(JAMULUS_ANDROID_VERSION_CODE) + !isEmpty(JAMULUS_ANDROID_VERSION_CODE) { + ANDROID_VERSION_CODE = $$JAMULUS_ANDROID_VERSION_CODE + } else:!contains(VERSION, .*dev.*) { + GIT_IS_WORK_TREE = $$system(git rev-parse --is-inside-work-tree 2>/dev/null) + GIT_IS_SHALLOW = $$system(git rev-parse --is-shallow-repository 2>/dev/null) + equals(GIT_IS_WORK_TREE, true):equals(GIT_IS_SHALLOW, false) { + GIT_REVISION_COUNT = $$system(git rev-list --count HEAD 2>/dev/null) + !isEmpty(GIT_REVISION_COUNT) { + ANDROID_VERSION_CODE = $$GIT_REVISION_COUNT + } + } + } message("Setting ANDROID_VERSION_NAME=$${ANDROID_VERSION_NAME} ANDROID_VERSION_CODE=$${ANDROID_VERSION_CODE}") # liboboe requires C++17 for std::timed_mutex @@ -274,6 +289,7 @@ win32 { src/android/androiddebug.cpp LIBS += -lOpenSLES + QMAKE_LFLAGS += -Wl,-z,max-page-size=16384 ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android DISTFILES += android/AndroidManifest.xml diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 0f58f79021..48b4a48a72 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -46,8 +46,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . --> - - + diff --git a/tools/android-build.sh b/tools/android-build.sh new file mode 100755 index 0000000000..6762b91e0a --- /dev/null +++ b/tools/android-build.sh @@ -0,0 +1,353 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2026 +# +# Author(s): +# Peter L Jones +# The Jamulus Development Team +# +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +# Apply workflow-style Android environment, optional local overrides, then run +# .github/autobuild/android.sh so build and get-artifacts share the same settings. + +set -euo pipefail + +SCRIPT_NAME="$(basename "$0")" +readonly SCRIPT_NAME +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +readonly PROJECT_DIR +readonly ANDROID_SH="${PROJECT_DIR}/.github/autobuild/android.sh" + +MANAGED_VARS=( + JAVA_HOME + ANDROID_SDK_ROOT + ANDROID_NDK_ROOT + ANDROID_BUILD_TOOLS + ANDROID_PLATFORM + QT_SELECT + QT_DIR + QT_VERSION + JAMULUS_BUILD_VERSION + BUILD_MODES + TARGET_ARCHS + JAMULUS_ANDROID_QMAKE_CONFIG + JAMULUS_ANDROID_MAKE_JOBS + JAMULUS_ANDROID_ARTIFACT_SUFFIX + JAMULUS_ANDROID_VERSION_CODE + JAMULUS_ANDROID_BUILD_DIR + JAMULUS_ANDROID_DEPLOY_DIR + COMMANDLINETOOLS_VERSION + ANDROID_NDK_VERSION + AQTINSTALL_VERSION + ANDROID_JAVA_VERSION +) + +error() { + printf '%s: %s\n' "$SCRIPT_NAME" "$1" >&2 + exit 1 +} + +apply_local_defaults() { + # Local developer layout from COMPILING.md. CI uses different /opt/android + # paths after android.sh setup. + : "${JAVA_HOME:=/usr/lib/jvm/java-${ANDROID_JAVA_VERSION:-11}-openjdk-amd64}" + : "${ANDROID_SDK_ROOT:=/opt/android-sdk}" + : "${ANDROID_NDK_ROOT:=${ANDROID_SDK_ROOT}/ndk/21.0.6113669}" + : "${ANDROID_BUILD_TOOLS:=}" + export QT_SELECT="${QT_VERSION}-android" + # android.sh derives QT_ANDROID_DIR itself as "${QT_DIR}/${QT_VERSION}/android" + : "${QT_DIR:=/opt/Qt}" + : "${BUILD_MODES:=debug release}" + : "${TARGET_ARCHS:=armeabi-v7a arm64-v8a x86 x86_64}" +} + +load_settings_file() { + local settings_file="$1" + + [[ -n "$settings_file" ]] || return 0 + [[ -f "$settings_file" ]] || error "settings file not found: $settings_file" + [[ -r "$settings_file" ]] || error "settings file is not readable: $settings_file" + printf 'Using settings file %s\n' "$settings_file" + set -a + # Developer-supplied KEY=value file; not shipped in the repository. + # shellcheck disable=SC1090 + source "$settings_file" + set +a +} + +export_managed_env() { + local var + for var in "${MANAGED_VARS[@]}"; do + if [[ -n "${!var+x}" ]]; then + # Export variable named $var + # shellcheck disable=SC2163 + export "$var" + fi + done +} + +ensure_java_on_path() { + if [[ -n "${JAVA_HOME:-}" && -d "${JAVA_HOME}/bin" ]]; then + case ":${PATH}:" in + *":${JAVA_HOME}/bin:"*) ;; + *) + PATH="${JAVA_HOME}/bin:${PATH}" + ;; + esac + export PATH + fi +} + +ensure_build_version() { + if [[ -z "${JAMULUS_BUILD_VERSION:-}" ]]; then + local jamulus_pro_version + jamulus_pro_version="$(sed -nE 's/^VERSION[[:space:]]*=[[:space:]]*([^[:space:]]+)[[:space:]]*$/\1/p' "${PROJECT_DIR}/Jamulus.pro")" + [[ -n "$jamulus_pro_version" ]] || error "cannot determine Jamulus.pro VERSION" + JAMULUS_BUILD_VERSION="$jamulus_pro_version" + if [[ "$jamulus_pro_version" == *dev* ]]; then + JAMULUS_BUILD_VERSION+="-$(git -C "$PROJECT_DIR" describe \ + --match=xxxxxxxxxxxxxxxxxxxx --always --abbrev --dirty)" + fi + export JAMULUS_BUILD_VERSION + fi + [[ ${JAMULUS_BUILD_VERSION} =~ [0-9]+\.[0-9]+\.[0-9]+ ]] || + error "JAMULUS_BUILD_VERSION is not a valid version string: ${JAMULUS_BUILD_VERSION}" +} + +print_resolved_env() { + local var + printf 'Resolved Android build environment:\n' + for var in "${MANAGED_VARS[@]}"; do + if [[ -z "${!var+x}" ]]; then + continue + fi + printf ' %s=%s\n' "$var" "${!var}" + done +} + +run_logged() { + if [[ -n "${LOG_FILE:-}" ]]; then + "$@" 2>&1 | tee -a "$LOG_FILE" + return "${PIPESTATUS[0]}" + fi + "$@" +} + +run_distclean() { + if [[ -f "${PROJECT_DIR}/Makefile" ]]; then + run_logged make -C "$PROJECT_DIR" distclean || : + fi + + validate_android_output_paths + + local generated_path + + for generated_path in "$BUILD_ROOT" "$DEPLOY_DIR"; do + rm -rf -- "$generated_path" + done + + for generated_path in "${LEGACY_ANDROID_OUTPUTS[@]}"; do + if [[ -e "$generated_path" || -L "$generated_path" ]]; then + rm -rf -- "$generated_path" + fi + done +} + +run_stage() { + local stage="$1" + case "$stage" in + setup | build | get-artifacts) + run_logged "$ANDROID_SH" "$stage" + ;; + distclean) + run_distclean + ;; + *) + error "unknown stage: $stage" + ;; + esac +} + +resolve_settings_file() { + local requested="$1" + if [[ -n "$requested" ]]; then + printf '%s' "$requested" + return + fi + if [[ -n "${JAMULUS_ANDROID_SETTINGS:-}" ]]; then + printf '%s' "$JAMULUS_ANDROID_SETTINGS" + return + fi + local default_settings_file="${PROJECT_DIR}/android-build_qt5.settings" + if [[ -f "$default_settings_file" ]]; then + printf '%s' "$default_settings_file" + return + fi + [[ -f "$default_settings_file" ]] && printf '%s' "$default_settings_file" +} + +usage() { + cat << EOF +Usage: $SCRIPT_NAME [options] [stage ...] + +Load local Android toolchain defaults (as in COMPILING.md), apply optional +overrides from a settings file, then run .github/autobuild/android.sh with the +same environment for every stage. JAMULUS_BUILD_VERSION is taken from +Jamulus.pro (plus the git hash for development versions) unless already set. + +Stages: + setup Install CI-style SDK/NDK/Qt under /opt (rarely needed locally) + distclean make distclean (if a Makefile exists) and remove Android build and deploy outputs + build Build selected debug/release packages + get-artifacts Rename packages into deploy/ + all distclean, build, and get-artifacts (default) + +Options: + -h, --help Show this help + --settings FILE Override file (default: android-build_qtVERSION.settings if present) + --stream STREAM Select the Qt 5 build (default: qt5) + --log FILE Also write combined stdout/stderr to FILE + --print-env Print the resolved environment and exit + --build-modes "MODES" Override BUILD_MODES (default: "debug release") + --archs "ARCHS" Override TARGET_ARCHS (default: "armeabi-v7a arm64-v8a x86 x86_64") + --jobs JOBS Limit parallel compiler jobs (default: nproc) + +Precedence: command-line options > settings file > existing environment > documented local defaults. +See tools/android-build_qt5.settings.example. +EOF +} + +SETTINGS_FILE="" +LOG_FILE="" +PRINT_ENV=0 +STAGES=() +OPTION_BUILD_MODES="" +OPTION_TARGET_ARCHS="" +OPTION_MAKE_JOBS="" +OPTION_STREAM="" + +while [[ $# -gt 0 ]]; do + case "$1" in + -h | --help) + usage + exit 0 + ;; + --settings) + [[ $# -ge 2 ]] || error "missing value for --settings" + SETTINGS_FILE="$2" + shift 2 + ;; + --build-modes) + [[ $# -ge 2 ]] || error "missing value for --build-modes" + OPTION_BUILD_MODES="$2" + shift 2 + ;; + --archs) + [[ $# -ge 2 ]] || error "missing value for --archs" + OPTION_TARGET_ARCHS="$2" + shift 2 + ;; + --jobs) + [[ $# -ge 2 ]] || error "missing value for --jobs" + [[ "$2" =~ ^[1-9][0-9]*$ ]] || error "--jobs must be a positive integer" + OPTION_MAKE_JOBS="$2" + shift 2 + ;; + --stream) + [[ $# -ge 2 ]] || error "missing value for --stream" + OPTION_STREAM="$2" + shift 2 + ;; + --print-env) + PRINT_ENV=1 + shift + ;; + --log) + [[ $# -ge 2 ]] || error "missing value for --log" + LOG_FILE="$2" + shift 2 + ;; + all) + STAGES+=(distclean build get-artifacts) + shift + ;; + setup | distclean | build | get-artifacts) + STAGES+=("$1") + shift + ;; + *) + error "unknown argument: $1" + ;; + esac +done + +if [[ ${#STAGES[@]} -eq 0 && "$PRINT_ENV" -eq 0 ]]; then + STAGES=(distclean build get-artifacts) +fi + +cd "$PROJECT_DIR" +[[ -x "$ANDROID_SH" || -f "$ANDROID_SH" ]] || error "cannot find $ANDROID_SH" + +JAMULUS_ANDROID_STREAM="${OPTION_STREAM:-${JAMULUS_ANDROID_STREAM:-qt5}}" +[[ "$JAMULUS_ANDROID_STREAM" == qt5 ]] || + error "unsupported Android build stream: $JAMULUS_ANDROID_STREAM" +ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" +EXPLICIT_COMMANDLINETOOLS_VERSION="${COMMANDLINETOOLS_VERSION:-}" +EXPLICIT_ANDROID_NDK_VERSION="${ANDROID_NDK_VERSION:-}" +EXPLICIT_ANDROID_PLATFORM="${ANDROID_PLATFORM:-}" +EXPLICIT_ANDROID_BUILD_TOOLS="${ANDROID_BUILD_TOOLS:-}" +EXPLICIT_AQTINSTALL_VERSION="${AQTINSTALL_VERSION:-}" +EXPLICIT_ANDROID_JAVA_VERSION="${ANDROID_JAVA_VERSION:-}" +EXPLICIT_QT_VERSION="${QT_VERSION:-}" +# shellcheck disable=SC1090 +source "$ANDROID_DEPENDENCIES" +[[ -n "$EXPLICIT_COMMANDLINETOOLS_VERSION" ]] && COMMANDLINETOOLS_VERSION="$EXPLICIT_COMMANDLINETOOLS_VERSION" +[[ -n "$EXPLICIT_ANDROID_NDK_VERSION" ]] && ANDROID_NDK_VERSION="$EXPLICIT_ANDROID_NDK_VERSION" +[[ -n "$EXPLICIT_ANDROID_PLATFORM" ]] && ANDROID_PLATFORM="$EXPLICIT_ANDROID_PLATFORM" +[[ -n "$EXPLICIT_ANDROID_BUILD_TOOLS" ]] && ANDROID_BUILD_TOOLS="$EXPLICIT_ANDROID_BUILD_TOOLS" +[[ -n "$EXPLICIT_AQTINSTALL_VERSION" ]] && AQTINSTALL_VERSION="$EXPLICIT_AQTINSTALL_VERSION" +[[ -n "$EXPLICIT_ANDROID_JAVA_VERSION" ]] && ANDROID_JAVA_VERSION="$EXPLICIT_ANDROID_JAVA_VERSION" +[[ -n "$EXPLICIT_QT_VERSION" ]] && QT_VERSION="$EXPLICIT_QT_VERSION" +load_settings_file "$(resolve_settings_file "$SETTINGS_FILE")" +[[ -n "$OPTION_BUILD_MODES" ]] && BUILD_MODES="$OPTION_BUILD_MODES" +[[ -n "$OPTION_TARGET_ARCHS" ]] && TARGET_ARCHS="$OPTION_TARGET_ARCHS" +[[ -n "$OPTION_MAKE_JOBS" ]] && export JAMULUS_ANDROID_MAKE_JOBS="$OPTION_MAKE_JOBS" +apply_local_defaults +export_managed_env +ensure_java_on_path +ensure_build_version +print_resolved_env + +# shellcheck disable=SC1090 +source "${PROJECT_DIR}/.github/autobuild/android-output-paths.sh" + +if [[ "$PRINT_ENV" -eq 1 ]]; then + exit 0 +fi + +if [[ -n "$LOG_FILE" ]]; then + mkdir -p "$(dirname "$LOG_FILE")" + : > "$LOG_FILE" + printf 'Logging to %s\n' "$LOG_FILE" +fi + +for stage in "${STAGES[@]}"; do + printf '=== %s ===\n' "$stage" + run_stage "$stage" +done diff --git a/tools/android-build_qt5.settings.example b/tools/android-build_qt5.settings.example new file mode 100644 index 0000000000..21ce47f893 --- /dev/null +++ b/tools/android-build_qt5.settings.example @@ -0,0 +1,22 @@ +# Copy to android-build_qt5.settings in the repository root (gitignored), or +# pass --settings /path/to/file. Values here override existing environment +# values and tools/android-build.sh defaults. Command-line options take +# precedence. + +# JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 +# ANDROID_SDK_ROOT=/opt/android-sdk +# ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk/21.0.6113669 +# ANDROID_BUILD_TOOLS=30.0.2 +# QT_DIR=/opt/Qt +# ANDROID_PLATFORM=android-30 + +# Narrow these for faster local rebuilds: +BUILD_MODES=release +TARGET_ARCHS=arm64-v8a + +# Optional qmake CONFIG values, space-separated: +# JAMULUS_ANDROID_QMAKE_CONFIG="serveronly disable_version_check" + +# Override the default `_qt5` artifact suffix if necessary: +# JAMULUS_ANDROID_ARTIFACT_SUFFIX=_custom +# Add machine-specific toolchain overrides to the ignored settings file. From e40a356d66c2cf1f8be79f5b4bb47e24881f7237 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Wed, 28 Oct 2026 18:13:55 +0000 Subject: [PATCH 3/5] Add Qt6 for Android (ZIPs, no .pro multi-ABIs) --- .github/autobuild/android-dependencies_qt6.sh | 13 + .github/autobuild/android.sh | 276 +++++++++++++++--- .github/workflows/autobuild.yml | 18 ++ COMPILING.md | 70 +++-- Jamulus.pro | 13 +- android/qt6/AndroidManifest.xml | 70 +++++ android/qt6/res | 1 + src/main.cpp | 36 ++- tools/android-build.sh | 19 +- tools/android-build_qt6.settings.example | 24 ++ 10 files changed, 459 insertions(+), 81 deletions(-) create mode 100644 .github/autobuild/android-dependencies_qt6.sh create mode 100644 android/qt6/AndroidManifest.xml create mode 120000 android/qt6/res create mode 100644 tools/android-build_qt6.settings.example diff --git a/.github/autobuild/android-dependencies_qt6.sh b/.github/autobuild/android-dependencies_qt6.sh new file mode 100644 index 0000000000..5da0130499 --- /dev/null +++ b/.github/autobuild/android-dependencies_qt6.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# The following version pinnings are semi-automatically checked for updates. +# Verify .github/workflows/bump-dependencies.yml when changing those manually: + +# Values are consumed by android.sh and the dependency cache key. +# shellcheck disable=SC2034 +COMMANDLINETOOLS_VERSION=6858069 +ANDROID_NDK_VERSION=r27d +ANDROID_PLATFORM=android-36 +ANDROID_BUILD_TOOLS=36.0.0 +AQTINSTALL_VERSION=3.3.0 +ANDROID_JAVA_VERSION=17 +QT_VERSION=6.10.2 diff --git a/.github/autobuild/android.sh b/.github/autobuild/android.sh index fae6f4495a..76a6f86495 100755 --- a/.github/autobuild/android.sh +++ b/.github/autobuild/android.sh @@ -58,8 +58,21 @@ fi PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" readonly PROJECT_DIR -ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" -DEFAULT_ARTIFACT_SUFFIX="_qt5" +JAMULUS_ANDROID_STREAM="${JAMULUS_ANDROID_STREAM:-qt5}" +case "$JAMULUS_ANDROID_STREAM" in + qt5) + ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" + DEFAULT_ARTIFACT_SUFFIX="_qt5" + ;; + qt6) + ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt6.sh" + DEFAULT_ARTIFACT_SUFFIX="_qt6" + ;; + *) + echo "Unsupported Android build stream: $JAMULUS_ANDROID_STREAM" >&2 + exit 1 + ;; +esac # Save environment before sourcing the dependencies file, so we can restore overrides. EXPLICIT_COMMANDLINETOOLS_VERSION="${COMMANDLINETOOLS_VERSION:-}" @@ -102,19 +115,35 @@ if [[ ! ${QT_VERSION:-} =~ [0-9]+\.[0-9]+\..* ]]; then exit 1 fi -[[ "${QT_VERSION}" =~ ^5\..* ]] || { - echo "The Qt 5 Android build requires Qt 5; received ${QT_VERSION}" >&2 +if [[ "$JAMULUS_ANDROID_STREAM" == qt5 && ! "${QT_VERSION}" =~ ^5\..* ]] || + [[ "$JAMULUS_ANDROID_STREAM" == qt6 && ! "${QT_VERSION}" =~ ^6\..* ]]; then + echo "Android stream ${JAMULUS_ANDROID_STREAM} is incompatible with Qt ${QT_VERSION}" >&2 exit 1 -} -QT_ANDROID_DIR="${QT_DIR}/${QT_VERSION}/android" -QT_ANDROIDDEPLOYQT="${QT_ANDROID_DIR}/bin/androiddeployqt" +fi +if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then + QT_ANDROID_DIR="${QT_DIR}/${QT_VERSION}/android" + QT_ANDROIDDEPLOYQT="${QT_ANDROID_DIR}/bin/androiddeployqt" + QT_HOST_PATH="${QT_ANDROID_DIR}" + QT_QMAKE="${QT_ANDROID_DIR}/bin/qmake" +else + QT_ANDROID_DIR="${QT_DIR}/${QT_VERSION}" + QT_ANDROIDDEPLOYQT="${QT_ANDROID_DIR}/gcc_64/bin/androiddeployqt" + QT_HOST_PATH="${QT_ANDROID_DIR}/gcc_64" + QT_QMAKE="" +fi readonly QT_ANDROID_DIR readonly QT_ANDROIDDEPLOYQT +export QT_HOST_PATH export QT_SELECT -QT_SELECT="${QT_VERSION}-$(basename "${QT_ANDROID_DIR}")" -export QTTOOLDIR="${QT_ANDROID_DIR}/bin" -export QTLIBDIR="${QT_ANDROID_DIR}/lib" +QT_SELECT="${QT_VERSION}-android" +if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then + export QTTOOLDIR="${QT_ANDROID_DIR}/bin" + export QTLIBDIR="${QT_ANDROID_DIR}/lib" +else + export QTTOOLDIR="${QT_HOST_PATH}/bin" + export QTLIBDIR="${QT_HOST_PATH}/lib" +fi # Only variables which are really needed by sub-commands are exported. # Definitions have to stay in a specific order due to dependencies. @@ -129,8 +158,6 @@ for var in JAMULUS_ANDROID_KEY_ALIAS JAMULUS_ANDROID_KEY_PASSWORD JAMULUS_ANDROI if [[ -n "${!var:-}" ]]; then echo $var='****'; fi done -readonly QT_QMAKE="${QT_ANDROID_DIR}/bin/qmake" - # shellcheck disable=SC1090 source "${PROJECT_DIR}/.github/autobuild/android-output-paths.sh" @@ -256,16 +283,42 @@ setup_android_ndk() { echo "${ANDROID_NDK_VERSION}" > "$ndk_version_marker" } +qt_android_arch() { + case "$1" in + armeabi-v7a) printf '%s' android_armv7 ;; + arm64-v8a) printf '%s' android_arm64_v8a ;; + x86) printf '%s' android_x86 ;; + x86_64) printf '%s' android_x86_64 ;; + *) + echo "Unsupported Android ABI: $1" >&2 + return 1 + ;; + esac +} + setup_qt() { + local target_arch + local qt_arch + # We may need to create the Qt installation directory and chown it to the runner user to fix permissions # (even after cache recovery) sudo mkdir -p "${QT_DIR}" sudo chown -R "$(whoami)" "${QT_DIR}" - # QT_QMAKE and QT_ANDROIDDEPLOYQT are under a version-named directory. - if [[ -x "${QT_QMAKE}" && -x "${QT_ANDROIDDEPLOYQT}" ]]; then - echo "Using Qt ${QT_VERSION} installation from previous run (actions/cache)" - return + if [[ -x "${QT_ANDROIDDEPLOYQT}" ]]; then + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 && -x "${QT_QMAKE}" ]]; then + echo "Using Qt ${QT_VERSION} installation from previous run (actions/cache)" + return + elif [[ "$JAMULUS_ANDROID_STREAM" == qt6 ]]; then + for target_arch in $TARGET_ARCHS; do + qt_arch="$(qt_android_arch "$target_arch")" + [[ -x "${QT_DIR}/${QT_VERSION}/${qt_arch}/bin/qmake" ]] || break + done + if [[ -x "${QT_DIR}/${QT_VERSION}/${qt_arch}/bin/qmake" ]]; then + echo "Using Qt ${QT_VERSION} installation for ${TARGET_ARCHS} from previous run (actions/cache)" + return + fi + fi fi echo "Installing Qt" @@ -283,14 +336,32 @@ setup_qt() { pip install "aqtinstall==${AQTINSTALL_VERSION}" # Install actual Android Qt: - local qt_archives=(qtbase qttools qttranslations qtandroidextras qtmultimedia) - python3 -m aqt install-qt --outputdir "${QT_DIR}" linux android "${QT_VERSION}" \ - --archives "${qt_archives[@]}" + local qt_archives=(qtbase qttools qttranslations) + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then + qt_archives+=(qtandroidextras qtmultimedia) + python3 -m aqt install-qt --outputdir "${QT_DIR}" linux android "${QT_VERSION}" \ + --archives "${qt_archives[@]}" + else + qt_archives+=(icu) + for target_arch in $TARGET_ARCHS; do + qt_arch="$(qt_android_arch "$target_arch")" + python3 -m aqt install-qt --outputdir "${QT_DIR}" linux android "${QT_VERSION}" "$qt_arch" \ + --autodesktop --archives "${qt_archives[@]}" --modules qtmultimedia + done + fi # Delete libraries, which we don't use, but which bloat the resulting package and might introduce unwanted dependencies. # iOS does not do this - leave for now, fix across all later. - find "$QT_ANDROID_DIR" -name 'libQt*Quick*.so' -delete - rm -rf "$QT_ANDROID_DIR/qml/" + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then + find "$QT_ANDROID_DIR" -name 'libQt*Quick*.so' -delete + rm -rf "$QT_ANDROID_DIR/qml/" + else + for target_arch in $TARGET_ARCHS; do + qt_arch="$(qt_android_arch "$target_arch")" + find "${QT_DIR}/${QT_VERSION}/${qt_arch}" -name 'libQt*Quick*.so' -delete + rm -rf "${QT_DIR}/${QT_VERSION}/${qt_arch}/qml/" + done + fi # deactivate and remove venv as aqt is no longer needed from here on deactivate @@ -332,6 +403,8 @@ validate_android_toolchain() { validate_signing() { local signing_setting + + [[ " $BUILD_MODES " == *" release "* ]] || return 0 [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}" ]] && echo "No Android keystore file specified" >&2 [[ -z "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] && echo "No Android keystore base64 specified" >&2 [[ -z "${JAMULUS_ANDROID_KEY_ALIAS:-}" ]] && echo "No Android keystore alias specified" >&2 @@ -361,7 +434,23 @@ validate_signing() { exit 1 } fi + validate_android_output_paths +} + +cleanup_signing_for_mode() { + if [[ -n "${ANDROID_KEYSTORE_CLEANUP_FILE:-}" ]]; then + rm -f -- "$ANDROID_KEYSTORE_CLEANUP_FILE" + unset ANDROID_KEYSTORE_CLEANUP_FILE + fi + trap - EXIT + unset ANDROID_KEYSTORE_FILE +} + +prepare_signing_for_mode() { + local build_mode="$1" + cleanup_signing_for_mode + [[ "$build_mode" == release ]] || return 0 if [[ -n "${JAMULUS_ANDROID_KEYSTORE:-}" || -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then prepare_keystore @@ -386,8 +475,16 @@ prepare_keystore() { exit 1 fi trap 'rm -f -- "$ANDROID_KEYSTORE_FILE"' EXIT + local original_umask + original_umask="$(umask)" + umask 077 + if ! printf '%s' "$JAMULUS_ANDROID_KEYSTORE_BASE64" | base64 --decode > "$ANDROID_KEYSTORE_FILE"; then + umask "$original_umask" + echo "Failed to decode Android keystore" >&2 + exit 1 + fi chmod 600 "$ANDROID_KEYSTORE_FILE" - printf '%s' "$JAMULUS_ANDROID_KEYSTORE_BASE64" | base64 --decode > "$ANDROID_KEYSTORE_FILE" + umask "$original_umask" fi } @@ -410,6 +507,8 @@ prepare_debug_keystore() { echo "Invalid Android debug keystore: $ANDROID_KEYSTORE_FILE" >&2 exit 1 fi + else + mkdir -p "$(dirname "${ANDROID_KEYSTORE_FILE}")" fi else if ! ANDROID_KEYSTORE_TEMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/jamulus-android-debug-signing.XXXXXX")"; then @@ -474,6 +573,72 @@ qmake5_qmake_make() { popd > /dev/null } +android_abi_apk_name() { + local build_mode="$1" + local target_arch="$2" + printf 'jamulus_%s_android_%s%s_%s.apk' \ + "$JAMULUS_BUILD_VERSION" "$build_mode" "$ARTIFACT_SUFFIX" "$target_arch" +} + +qmake6_qmake_make() { + local build_mode="$1" + shift + local build_dir="$1" + shift + local -n _p="$1" + shift + local qmake_config=("$@") + local -a target_archs + local target_arch + local qt_arch + local qmake6_qmake + local arch_build_dir + local apk_path + local apk_name + local -a apk_paths + local -a package_args=("${_p[@]}") + + read -r -a target_archs <<< "${TARGET_ARCHS}" + for target_arch in "${target_archs[@]}"; do + qt_arch="$(qt_android_arch "$target_arch")" + qmake6_qmake="${QT_DIR}/${QT_VERSION}/${qt_arch}/bin/qmake" + [[ -x "$qmake6_qmake" ]] || { + echo "Qt 6 qmake not found for target ABI ${target_arch}: ${qmake6_qmake}" >&2 + exit 1 + } + + arch_build_dir="${build_dir}/${target_arch}" + mkdir -p "$arch_build_dir" + pushd "$arch_build_dir" > /dev/null + "$qmake6_qmake" "${PROJECT_DIR}/Jamulus.pro" -spec android-clang "${qmake_config[@]}" \ + ANDROID_ABIS="${target_arch}" ANDROID_TARGET_SDK_VERSION="${ANDROID_PLATFORM#android-}" + "${ANDROID_NDK_MAKE}" -j "$MAKE_JOBS" + "${ANDROID_NDK_MAKE}" INSTALL_ROOT="${arch_build_dir}" install + + if [[ "$build_mode" == release && -n "${ANDROID_KEYSTORE_FILE:-}" ]]; then + export QT_ANDROID_KEYSTORE_PATH="${ANDROID_KEYSTORE_FILE}" + export QT_ANDROID_KEYSTORE_ALIAS="${JAMULUS_ANDROID_KEY_ALIAS}" + export QT_ANDROID_KEYSTORE_STORE_PASS="${JAMULUS_ANDROID_KEYSTORE_PASSWORD}" + export QT_ANDROID_KEYSTORE_KEY_PASS="${JAMULUS_ANDROID_KEY_PASSWORD:-}" + package_args+=(--sign) + fi + "${QT_ANDROIDDEPLOYQT}" --verbose --input android-Jamulus-deployment-settings.json \ + --output "$arch_build_dir" "${package_args[@]}" + unset QT_ANDROID_KEYSTORE_PATH QT_ANDROID_KEYSTORE_ALIAS QT_ANDROID_KEYSTORE_STORE_PASS QT_ANDROID_KEYSTORE_KEY_PASS + + mapfile -t apk_paths < <(find "${arch_build_dir}/build/outputs" -type f -name '*.apk' -print) + if [[ ${#apk_paths[@]} -ne 1 ]]; then + echo "Expected one Android APK for ${build_mode}/${target_arch}, found ${#apk_paths[@]}" >&2 + exit 1 + fi + apk_path="${apk_paths[0]}" + mkdir -p "${build_dir}/abi-apks" + apk_name="$(android_abi_apk_name "$build_mode" "$target_arch")" + mv "$apk_path" "${build_dir}/abi-apks/${apk_name}" + popd > /dev/null + done +} + build_app() { local build_mode="$1" local build_dir="${BUILD_ROOT}/${build_mode}" @@ -489,16 +654,16 @@ build_app() { package_args+=(--android-platform "${ANDROID_PLATFORM}" --jdk "${JAVA_HOME}") if [[ "$build_mode" == release ]]; then package_args+=(--release) - if [[ -n "${ANDROID_KEYSTORE_FILE:-}" ]]; then - local detected_keystore_type - detected_keystore_type="$(keystore_type "${ANDROID_KEYSTORE_FILE}" "${JAMULUS_ANDROID_KEYSTORE_PASSWORD}")" || detected_keystore_type="unknown" + fi + if [[ "$build_mode" == release && -n "${ANDROID_KEYSTORE_FILE:-}" ]]; then + local detected_keystore_type + detected_keystore_type="$(keystore_type "${ANDROID_KEYSTORE_FILE}" "${JAMULUS_ANDROID_KEYSTORE_PASSWORD}")" || detected_keystore_type="unknown" - if [[ "$detected_keystore_type" == "PKCS12" ]]; then - package_args+=(--storetype PKCS12) - echo "Android release signing: forcing --storetype PKCS12 for PKCS12 keystore" - else - echo "Android release signing: leaving keystore type unspecified for ${detected_keystore_type} keystore" - fi + if [[ "$detected_keystore_type" == "PKCS12" ]]; then + package_args+=(--storetype PKCS12) + echo "Android release signing: forcing --storetype PKCS12 for PKCS12 keystore" + else + echo "Android release signing: leaving keystore type unspecified for ${detected_keystore_type} keystore" fi fi @@ -513,7 +678,11 @@ build_app() { rm -rf "${build_dir}" mkdir -p "${build_dir}" - qmake5_qmake_make "$build_mode" "${build_dir}" package_args "${qmake_config[@]}" + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then + qmake5_qmake_make "$build_mode" "${build_dir}" package_args "${qmake_config[@]}" + else + qmake6_qmake_make "$build_mode" "${build_dir}" package_args "${qmake_config[@]}" + fi } pass_artifact_to_job() { @@ -528,21 +697,44 @@ pass_artifact_to_job() { mkdir -p "${DEPLOY_DIR}" local artifact_number=1 local build_mode + local target_arch local artifact local package_path + local -a target_archs + local -a apk_paths for build_mode in $BUILD_MODES; do - artifact="jamulus_${JAMULUS_BUILD_VERSION}_android_${build_mode}${ARTIFACT_SUFFIX}.apk" - if [[ "$build_mode" == debug ]]; then - package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-debug.apk' -print -quit)" + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then + artifact="jamulus_${JAMULUS_BUILD_VERSION}_android_${build_mode}${ARTIFACT_SUFFIX}.apk" + if [[ "$build_mode" == debug ]]; then + package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-debug.apk' -print -quit)" + else + package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-signed.apk' -print -quit)" + fi + [[ -n "$package_path" ]] || { + echo "No Android APK was produced for ${build_mode}" >&2 + exit 1 + } + mv "$package_path" "${DEPLOY_DIR}/${artifact}" else - package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-signed.apk' -print -quit)" + artifact="jamulus_${JAMULUS_BUILD_VERSION}_android_${build_mode}${ARTIFACT_SUFFIX}.zip" + read -r -a target_archs <<< "${TARGET_ARCHS}" + apk_paths=() + for target_arch in "${target_archs[@]}"; do + package_path="${BUILD_ROOT}/${build_mode}/abi-apks/$(android_abi_apk_name "$build_mode" "$target_arch")" + [[ -f "$package_path" ]] || { + echo "Missing Android APK for ${build_mode}/${target_arch}" >&2 + exit 1 + } + apk_paths+=("$package_path") + done + [[ ${#apk_paths[@]} -eq ${#target_archs[@]} ]] || { + echo "Expected one APK per selected ABI for ${build_mode}" >&2 + exit 1 + } + rm -f "${DEPLOY_DIR}/${artifact}" + zip -q -j "${DEPLOY_DIR}/${artifact}" "${apk_paths[@]}" fi - [[ -n "$package_path" ]] || { - echo "No Android APK was produced for ${build_mode}" >&2 - exit 1 - } - mv "$package_path" "${DEPLOY_DIR}/${artifact}" if [[ -n "${GITHUB_OUTPUT:-}" ]]; then echo "artifact_${artifact_number}=${artifact}" >> "$GITHUB_OUTPUT" else @@ -564,7 +756,9 @@ case "${1:-}" in validate_android_toolchain validate_signing for build_mode in $BUILD_MODES; do + prepare_signing_for_mode "$build_mode" build_app "$build_mode" + cleanup_signing_for_mode done ;; get-artifacts) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 26940a3db3..33d64bef23 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -206,6 +206,14 @@ jobs: # Jamulus.pro needs to count git history length for android versioning: checkout_fetch_depth: '0' + - config_name: Android Qt6 ABI APK ZIPs (experimental) + target_os: android + building_on_os: ubuntu-22.04 + base_command: JAVA_HOME= QT_DIR= ANDROID_NDK_ROOT= ANDROID_SDK_ROOT= JAMULUS_ANDROID_STREAM=qt6 ./.github/autobuild/android.sh + run_codeql: false + dependency_cache_key: qt6 + checkout_fetch_depth: '0' + - config_name: Linux .deb amd64 (artifacts+codeQL) target_os: linux building_on_os: ubuntu-22.04 @@ -347,6 +355,16 @@ jobs: ~/android-ndk key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/autobuild/android-dependencies_qt5.sh') }}-${{ matrix.config.dependency_cache_key }} + - name: Cache Android Qt6 dependencies + if: matrix.config.target_os == 'android' && matrix.config.dependency_cache_key == 'qt6' + uses: actions/cache@v6 + with: + path: | + ~/qt + ~/android-sdk + ~/android-ndk + key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/autobuild/android-dependencies_qt6.sh') }}-${{ matrix.config.dependency_cache_key }} + - name: Set up build dependencies for ${{ matrix.config.config_name }} run: ${{ matrix.config.base_command }} setup env: diff --git a/COMPILING.md b/COMPILING.md index d4abdb105d..bf62991f3f 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -192,41 +192,49 @@ If you want to build the installer, please run the `deploy_mac.sh` script: `./ma ## Android -Jamulus's Android side-load build uses Qt 5 and produces an APK: +Android builds are available in two independent streams: -| Qt | Package | Java | NDK | Build Tools | Compile platform / target SDK | -| -- | ------- | ---- | --- | ----------- | ----------------------------- | -| 5.15.2 | APK | 8 | r21d (21.0.6113669) | 30.0.2 | Android 11 / API 30 | - -The APK supports devices from Android 5.0/API 21. - -- Install Qt 5.15.2 with `qtbase`, `qttools`, `qttranslations`, - `qtandroidextras`, and `qtmultimedia`, plus JDK 8, Android NDK r21d, - Android SDK Platform 30, and Build Tools 30.0.2. The GitHub workflow installs - these dependencies on its runner; local builds use the installed toolchain. +| Stream | Qt | Package | Java | NDK | Build Tools | Compile / target SDK | +| ------ | -- | ------- | ---- | --- | ----------- | ------------------- | ------------------------- | +| `qt5` | 5.15.2 | Multi-ABI APK | 8 | r21d (21.0.6113669) | 30.0.2 | Android 11 / API 30 | API 21-31 | +| `qt6` | 6.10.2 | One APK per ABI, ZIPped | 17 | r27d (27.3.13750724) | 36.0.0 | Android 16 / API 36 | As of Jamulus 4.0.0, the Android package ID is `app.jamulus.jamulus`. Prior installation using the former `com.github.jamulussoftware.jamulus` ID will not be upgraded in-place. (Users must uninstall the former package before installing the new one, losing their settings). + +The compile/target SDK is the SDK level used to build and target the app, not +the full Android compatibility range supported by Qt: +- Qt 5 targets API 30 within its Android 5.0-12 / API 21-31 range. +- Qt 6 targets API 36 within its Android 9-16 / API 28-36 range. + +- Install the Qt, Android SDK, NDK, and JDK versions for the selected stream. + The GitHub workflow installs these dependencies on its runner; local builds + use the installed toolchain. Qt 5 needs `qtbase`, `qttools`, + `qttranslations`, `qtandroidextras`, and `qtmultimedia`. Qt 6 needs + `qtbase`, `qttools`, `qttranslations`, and the `qtmultimedia` module, with + Android kits for each selected ABI and a `gcc_64` host kit. - Make sure the Jamulus submodules are present, notably oboe: `git submodule update --init --recursive` ### Local builds Use `tools/android-build.sh` for local builds. It selects the toolchain for the -Qt 5 profile, loads optional machine-specific overrides, sets +selected profile, loads optional machine-specific overrides, sets `JAMULUS_BUILD_VERSION` from `Jamulus.pro` (and the git hash for development versions), and passes the same environment to every `android.sh` stage. -Create an ignored settings file for local toolchain overrides: +Create an ignored settings file for each stream you plan to use: ```bash cp tools/android-build_qt5.settings.example android-build_qt5.settings +cp tools/android-build_qt6.settings.example android-build_qt6.settings ``` -The Qt 5 wrapper loads `android-build_qt5.settings` by default. Set -machine-specific toolchain paths and ABI/mode subsets there. Inspect the -resolved environment with `--print-env`. +The wrapper loads `android-build_qt5.settings` or +`android-build_qt6.settings` by default. Set machine-specific toolchain paths +and ABI/mode subsets in the matching file. Inspect resolved values with +`--print-env`. Build Qt 5 APKs, which are suitable for temporary or release side-loading: @@ -234,12 +242,19 @@ Build Qt 5 APKs, which are suitable for temporary or release side-loading: tools/android-build.sh --stream qt5 --log android-qt5.log ``` +Build experimental Qt 6 APK ZIPs with: + +```bash +tools/android-build.sh --stream qt6 --log android-qt6.log +``` + ### Build options -- The Android driver defaults to all four ABIs and both debug and release modes. - Build outputs are written below - `android-build/debug/` and `android-build/release/`; running `get-artifacts` - moves them to `deploy/`. Artifacts use the `_qt5` suffix. +- Both streams default to all four ABIs and debug and release modes. Qt 5 + artifacts are multi-ABI APKs with the `_qt5.apk` suffix. Qt 6 builds a + standalone APK for each ABI and exports one `_qt6.zip` per mode; each ZIP + contains exactly the selected ABIs. Build outputs are under + `android-build//`, and `get-artifacts` places final files in `deploy/`. - Remove all generated Android build and deployment outputs with: ```bash @@ -253,9 +268,8 @@ tools/android-build.sh --stream qt5 --log android-qt5.log Select a subset of architectures with `TARGET_ARCHS`: ```bash - BUILD_MODES=release \ - TARGET_ARCHS="arm64-v8a x86_64" \ - tools/android-build.sh build get-artifacts + tools/android-build.sh --stream qt6 --build-modes release \ + --archs "arm64-v8a x86_64" build get-artifacts ``` Add qmake configuration values with `JAMULUS_ANDROID_QMAKE_CONFIG`: @@ -266,7 +280,8 @@ tools/android-build.sh --stream qt5 --log android-qt5.log ``` Set `ANDROID_NDK_ROOT` or `QT_DIR` to use different installed toolchains. - Set `ANDROID_PLATFORM` to select the Android SDK platform. + Set `ANDROID_PLATFORM` to select the Android SDK platform. `BUILD_MODES` + and `TARGET_ARCHS` can also be set in the stream's settings file. - Debug builds are packaged as debuggable APKs. Local release builds use a temporary debug keystore by default; it is deleted after the build. Set `JAMULUS_ANDROID_DEBUG_KEYSTORE` to retain and reuse a debug keystore. An @@ -277,7 +292,12 @@ tools/android-build.sh --stream qt5 --log android-qt5.log version code for non-development versions. Development builds default to version code `1`. Set `JAMULUS_ANDROID_VERSION_CODE` when a build needs an explicit positive version code. -- An APK can be installed directly with `adb`. +- Release builds use supplied Android keystore credentials when configured; + debug builds ignore them and use normal debug signing. Without a supplied + key, release builds use a temporary debug key and are not suitable for + updating a retained production installation. +- Qt 5 APKs can be installed directly with `adb`. Extract a Qt 6 ABI APK from + its ZIP before installing it. ## Compile time arguments diff --git a/Jamulus.pro b/Jamulus.pro index 299688f269..e14bcc2644 100644 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -275,7 +275,9 @@ win32 { # liboboe requires C++17 for std::timed_mutex CONFIG += c++17 - QT += androidextras + versionAtMost(QT_VERSION, 5.99.99) { + QT += androidextras + } # enabled only for debugging on android devices DEFINES += ANDROIDDEBUG @@ -290,8 +292,13 @@ win32 { LIBS += -lOpenSLES QMAKE_LFLAGS += -Wl,-z,max-page-size=16384 - ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android - DISTFILES += android/AndroidManifest.xml + greaterThan(QT_MAJOR_VERSION, 5) { + ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android/qt6 + DISTFILES += android/qt6/AndroidManifest.xml + } else { + ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android + DISTFILES += android/AndroidManifest.xml + } # if compiling for android you need to use Oboe library which is included as a git submodule # make sure you git pull with submodules to pull the latest Oboe library diff --git a/android/qt6/AndroidManifest.xml b/android/qt6/AndroidManifest.xml new file mode 100644 index 0000000000..f489746dc0 --- /dev/null +++ b/android/qt6/AndroidManifest.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/qt6/res b/android/qt6/res new file mode 120000 index 0000000000..85ee702340 --- /dev/null +++ b/android/qt6/res @@ -0,0 +1 @@ +../res \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5f9f8267e6..f53bf73a1a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,8 +61,10 @@ # include "testbench.h" #endif #include "util.h" -#ifdef ANDROID +#if defined( ANDROID ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) # include +#elif defined( ANDROID ) && QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 ) +# include #endif #if defined( Q_OS_MACOS ) # include "mac/activity.h" @@ -889,14 +891,18 @@ int main ( int argc, char** argv ) bIsClient = true; // Client only - TODO: maybe a switch in interface to change to server? // bUseMultithreading = true; - QApplication* pApp = new QApplication ( argc, argv ); + QApplication* pApp = new QApplication ( argc, argv ); # else QCoreApplication* pApp = bUseGUI ? new QApplication ( argc, argv ) : new QCoreApplication ( argc, argv ); # endif #endif -#ifdef ANDROID - // special Android coded needed for record audio permission handling +#if defined( ANDROID ) && QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 ) + bool bMicrophonePermissionGranted = true; +#endif + +#if defined( ANDROID ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + // Qt 5 requests this permission synchronously before client construction. auto result = QtAndroid::checkPermission ( QString ( "android.permission.RECORD_AUDIO" ) ); if ( result == QtAndroid::PermissionResult::Denied ) @@ -908,6 +914,26 @@ int main ( int argc, char** argv ) return 0; } } +#elif defined( ANDROID ) && QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 ) + QMicrophonePermission microphonePermission; + const Qt::PermissionStatus microphonePermissionStatus = pApp->checkPermission ( microphonePermission ); + if ( microphonePermissionStatus == Qt::PermissionStatus::Denied ) + { + return 0; + } + if ( microphonePermissionStatus == Qt::PermissionStatus::Undetermined ) + { + bMicrophonePermissionGranted = false; + pApp->requestPermission ( microphonePermission, pApp, [&bMicrophonePermissionGranted, pApp] ( const QPermission& permission ) { + bMicrophonePermissionGranted = permission.status() == Qt::PermissionStatus::Granted; + pApp->quit(); + } ); + pApp->exec(); + if ( !bMicrophonePermissionGranted ) + { + return 0; + } + } #endif #ifdef _WIN32 @@ -945,7 +971,7 @@ int main ( int argc, char** argv ) qWarning() << "No JSON-RPC support in this build."; } #else - CRpcServer* pRpcServer = nullptr; + CRpcServer* pRpcServer = nullptr; if ( iJsonRpcPortNumber != INVALID_PORT ) { diff --git a/tools/android-build.sh b/tools/android-build.sh index 6762b91e0a..3647a17e44 100755 --- a/tools/android-build.sh +++ b/tools/android-build.sh @@ -48,6 +48,7 @@ MANAGED_VARS=( TARGET_ARCHS JAMULUS_ANDROID_QMAKE_CONFIG JAMULUS_ANDROID_MAKE_JOBS + JAMULUS_ANDROID_STREAM JAMULUS_ANDROID_ARTIFACT_SUFFIX JAMULUS_ANDROID_VERSION_CODE JAMULUS_ANDROID_BUILD_DIR @@ -68,9 +69,13 @@ apply_local_defaults() { # paths after android.sh setup. : "${JAVA_HOME:=/usr/lib/jvm/java-${ANDROID_JAVA_VERSION:-11}-openjdk-amd64}" : "${ANDROID_SDK_ROOT:=/opt/android-sdk}" - : "${ANDROID_NDK_ROOT:=${ANDROID_SDK_ROOT}/ndk/21.0.6113669}" + if [[ "$JAMULUS_ANDROID_STREAM" == qt6 ]]; then + : "${ANDROID_NDK_ROOT:=${ANDROID_SDK_ROOT}/ndk/27.3.13750724}" + else + : "${ANDROID_NDK_ROOT:=${ANDROID_SDK_ROOT}/ndk/21.0.6113669}" + fi : "${ANDROID_BUILD_TOOLS:=}" - export QT_SELECT="${QT_VERSION}-android" + export QT_SELECT="${QT_SELECT:-${QT_VERSION}-android}" # android.sh derives QT_ANDROID_DIR itself as "${QT_DIR}/${QT_VERSION}/android" : "${QT_DIR:=/opt/Qt}" : "${BUILD_MODES:=debug release}" @@ -194,7 +199,7 @@ resolve_settings_file() { printf '%s' "$JAMULUS_ANDROID_SETTINGS" return fi - local default_settings_file="${PROJECT_DIR}/android-build_qt5.settings" + local default_settings_file="${PROJECT_DIR}/android-build_${JAMULUS_ANDROID_STREAM}.settings" if [[ -f "$default_settings_file" ]]; then printf '%s' "$default_settings_file" return @@ -221,7 +226,7 @@ Stages: Options: -h, --help Show this help --settings FILE Override file (default: android-build_qtVERSION.settings if present) - --stream STREAM Select the Qt 5 build (default: qt5) + --stream STREAM Select the Qt 5 or Qt 6 build (default: qt5) --log FILE Also write combined stdout/stderr to FILE --print-env Print the resolved environment and exit --build-modes "MODES" Override BUILD_MODES (default: "debug release") @@ -229,7 +234,7 @@ Options: --jobs JOBS Limit parallel compiler jobs (default: nproc) Precedence: command-line options > settings file > existing environment > documented local defaults. -See tools/android-build_qt5.settings.example. +See the matching tools/android-build_qtVERSION.settings.example. EOF } @@ -305,9 +310,9 @@ cd "$PROJECT_DIR" [[ -x "$ANDROID_SH" || -f "$ANDROID_SH" ]] || error "cannot find $ANDROID_SH" JAMULUS_ANDROID_STREAM="${OPTION_STREAM:-${JAMULUS_ANDROID_STREAM:-qt5}}" -[[ "$JAMULUS_ANDROID_STREAM" == qt5 ]] || +[[ "$JAMULUS_ANDROID_STREAM" == qt5 || "$JAMULUS_ANDROID_STREAM" == qt6 ]] || error "unsupported Android build stream: $JAMULUS_ANDROID_STREAM" -ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" +ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_${JAMULUS_ANDROID_STREAM}.sh" EXPLICIT_COMMANDLINETOOLS_VERSION="${COMMANDLINETOOLS_VERSION:-}" EXPLICIT_ANDROID_NDK_VERSION="${ANDROID_NDK_VERSION:-}" EXPLICIT_ANDROID_PLATFORM="${ANDROID_PLATFORM:-}" diff --git a/tools/android-build_qt6.settings.example b/tools/android-build_qt6.settings.example new file mode 100644 index 0000000000..5ffc5b0625 --- /dev/null +++ b/tools/android-build_qt6.settings.example @@ -0,0 +1,24 @@ +# Copy to android-build_qt6.settings in the repository root (gitignored), or +# pass --settings /path/to/file. Values here override existing environment +# values and tools/android-build.sh defaults. Command-line options take +# precedence. + +# JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 +# ANDROID_SDK_ROOT=/opt/android-sdk +# ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk/27.3.13750724 +# ANDROID_BUILD_TOOLS=36.0.0 +# QT_DIR=/opt/Qt +# ANDROID_PLATFORM=android-36 + +# Defaults to all four ABIs and both build modes. +# BUILD_MODES=release +TARGET_ARCHS=arm64-v8a + +# Optional qmake CONFIG values, space-separated: +# JAMULUS_ANDROID_QMAKE_CONFIG="serveronly disable_version_check" + +# Optional release signing (keep these outside the repository): +# JAMULUS_ANDROID_KEYSTORE=${HOME}/Jamulus/jamulus-upload.jks +# JAMULUS_ANDROID_KEY_ALIAS=jamulus +# JAMULUS_ANDROID_KEYSTORE_PASSWORD=production-password +# JAMULUS_ANDROID_KEY_PASSWORD=production-password \ No newline at end of file From 14f3fc35dd43c165d2d50d54360bfe9e0a85396d Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 22 Nov 2026 18:44:59 +0000 Subject: [PATCH 4/5] Add Qt5 Play Store (experimental pljones test package) --- .../android-dependencies_qt5-play-store.sh | 9 + .github/autobuild/android-play-store.sh | 56 +++++++ .github/autobuild/android.sh | 85 +++++++++- .github/workflows/autobuild.yml | 157 +++++++++++++++++- .gitignore | 2 + COMPILING.md | 53 +++++- android/AndroidManifest.xml | 4 +- android/play-store/build.gradle | 72 ++++++++ android/play-store/gradle-wrapper.properties | 5 + android/play-store/gradlew | 12 ++ android/qt6/AndroidManifest.xml | 2 +- tools/android-build.sh | 52 +++++- ...roid-build_qt5-play-store.settings.example | 11 ++ 13 files changed, 491 insertions(+), 29 deletions(-) create mode 100644 .github/autobuild/android-dependencies_qt5-play-store.sh create mode 100755 .github/autobuild/android-play-store.sh create mode 100644 android/play-store/build.gradle create mode 100644 android/play-store/gradle-wrapper.properties create mode 100644 android/play-store/gradlew create mode 100644 tools/android-build_qt5-play-store.settings.example diff --git a/.github/autobuild/android-dependencies_qt5-play-store.sh b/.github/autobuild/android-dependencies_qt5-play-store.sh new file mode 100644 index 0000000000..39c7924b82 --- /dev/null +++ b/.github/autobuild/android-dependencies_qt5-play-store.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# shellcheck disable=SC2034 +COMMANDLINETOOLS_VERSION=6858069 +ANDROID_NDK_VERSION=r21d +ANDROID_PLATFORM=android-36 +ANDROID_BUILD_TOOLS=36.0.0 +AQTINSTALL_VERSION=3.3.0 +ANDROID_JAVA_VERSION=17 +QT_VERSION=5.15.2 diff --git a/.github/autobuild/android-play-store.sh b/.github/autobuild/android-play-store.sh new file mode 100755 index 0000000000..5ecc34ca81 --- /dev/null +++ b/.github/autobuild/android-play-store.sh @@ -0,0 +1,56 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2026 +# +# Author(s): +# The Jamulus Development Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +# +# Select the single Qt 5 release App Bundle for Google Play upload. +# Usage: android-play-store.sh [INPUT_DIR [OUTPUT_DIR]] (default: deploy play-store) + +set -eu + +set -o pipefail + +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +readonly PROJECT_DIR +readonly INPUT_DIR="${1:-${JAMULUS_ANDROID_DEPLOY_DIR:-${PROJECT_DIR}/deploy}}" +readonly OUTPUT_DIR="${2:-${PROJECT_DIR}/play-store}" + +[[ -d "$INPUT_DIR" ]] || { + echo "Input directory does not exist: $INPUT_DIR" >&2 + exit 1 +} + +# Debug bundles and the Qt 6 APK ZIPs are never uploadable. +mapfile -t BUNDLES < <(find "$INPUT_DIR" -maxdepth 1 -type f -name 'jamulus_*_android_release_qt5.aab' -print) +if [[ ${#BUNDLES[@]} -ne 1 ]]; then + echo "Expected exactly one Qt 5 release Android App Bundle in ${INPUT_DIR}, found ${#BUNDLES[@]}" >&2 + exit 1 +fi + +mkdir -p "$OUTPUT_DIR" +rm -f -- "${OUTPUT_DIR}"/*.aab +cp -- "${BUNDLES[0]}" "${OUTPUT_DIR}/" +release_file="${OUTPUT_DIR}/$(basename "${BUNDLES[0]}")" + +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "release_file=${release_file}" >> "$GITHUB_OUTPUT" +else + echo "$release_file" +fi diff --git a/.github/autobuild/android.sh b/.github/autobuild/android.sh index 76a6f86495..0bee53d8b3 100755 --- a/.github/autobuild/android.sh +++ b/.github/autobuild/android.sh @@ -59,9 +59,18 @@ PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" readonly PROJECT_DIR JAMULUS_ANDROID_STREAM="${JAMULUS_ANDROID_STREAM:-qt5}" +JAMULUS_ANDROID_PLAY_STORE_BUILD="${JAMULUS_ANDROID_PLAY_STORE_BUILD:-false}" +[[ "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true || "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == false ]] || { + echo "JAMULUS_ANDROID_PLAY_STORE_BUILD must be true or false" >&2 + exit 1 +} case "$JAMULUS_ANDROID_STREAM" in qt5) - ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" + if [[ "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true ]]; then + ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5-play-store.sh" + else + ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5.sh" + fi DEFAULT_ARTIFACT_SUFFIX="_qt5" ;; qt6) @@ -161,12 +170,19 @@ done # shellcheck disable=SC1090 source "${PROJECT_DIR}/.github/autobuild/android-output-paths.sh" -readonly BUILD_MODES="${BUILD_MODES:-debug release}" +DEFAULT_BUILD_MODES="debug release" +DEFAULT_PACKAGE_FORMAT=apk +if [[ "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true ]]; then + DEFAULT_BUILD_MODES=release + DEFAULT_PACKAGE_FORMAT=aab +fi +readonly BUILD_MODES="${BUILD_MODES:-${DEFAULT_BUILD_MODES}}" readonly QMAKE_CONFIG="${JAMULUS_ANDROID_QMAKE_CONFIG:-}" MAX_MAKE_JOBS="$(nproc)" readonly MAX_MAKE_JOBS readonly MAKE_JOBS="${JAMULUS_ANDROID_MAKE_JOBS:-${MAX_MAKE_JOBS}}" readonly ARTIFACT_SUFFIX="${JAMULUS_ANDROID_ARTIFACT_SUFFIX:-${DEFAULT_ARTIFACT_SUFFIX}}" +readonly PACKAGE_FORMAT="${JAMULUS_ANDROID_PACKAGE_FORMAT:-${DEFAULT_PACKAGE_FORMAT}}" if [[ ! "$MAKE_JOBS" =~ ^[1-9][0-9]*$ ]] || ((MAKE_JOBS > MAX_MAKE_JOBS)); then echo "JAMULUS_ANDROID_MAKE_JOBS must be a positive integer no greater than ${MAX_MAKE_JOBS}" >&2 @@ -383,6 +399,36 @@ validate_build_mode() { done } +validate_package_format() { + if [[ "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true && "$PACKAGE_FORMAT" != aab ]]; then + echo "JAMULUS_ANDROID_PLAY_STORE_BUILD=true requires JAMULUS_ANDROID_PACKAGE_FORMAT=aab" >&2 + exit 1 + fi + + case "$PACKAGE_FORMAT" in + apk) ;; + aab) + # Only the Qt 5 build can produce a single multi-ABI bundle; Qt 6 builds one APK per ABI. + [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]] || { + echo "JAMULUS_ANDROID_PACKAGE_FORMAT=aab requires the qt5 stream" >&2 + exit 1 + } + [[ "$BUILD_MODES" == release ]] || { + echo "JAMULUS_ANDROID_PACKAGE_FORMAT=aab requires BUILD_MODES=release" >&2 + exit 1 + } + [[ "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true ]] || { + echo "AAB builds require JAMULUS_ANDROID_PLAY_STORE_BUILD=true" >&2 + exit 1 + } + ;; + *) + echo "Unsupported Android package format: $PACKAGE_FORMAT" >&2 + exit 1 + ;; + esac +} + validate_android_toolchain() { [[ -f "${ANDROID_NDK_ROOT}/source.properties" ]] || { echo "Selected Android NDK is not installed: ${ANDROID_NDK_ROOT}" >&2 @@ -405,6 +451,11 @@ validate_signing() { local signing_setting [[ " $BUILD_MODES " == *" release "* ]] || return 0 + # A bundle for store upload must never fall back to the generated debug key. + [[ "$PACKAGE_FORMAT" != aab || -n "${JAMULUS_ANDROID_KEYSTORE:-}${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] || { + echo "An Android App Bundle requires a release keystore" >&2 + exit 1 + } [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}" ]] && echo "No Android keystore file specified" >&2 [[ -z "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] && echo "No Android keystore base64 specified" >&2 [[ -z "${JAMULUS_ANDROID_KEY_ALIAS:-}" ]] && echo "No Android keystore alias specified" >&2 @@ -557,10 +608,20 @@ qmake5_qmake_make() { local qmake_config=("$@") local -a package_args=("${_p[@]}") + if [[ "$PACKAGE_FORMAT" == aab && "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true ]]; then + cp "${PROJECT_DIR}/android/play-store/build.gradle" \ + "${QT_ANDROID_DIR}/src/android/templates/build.gradle" + cp "${PROJECT_DIR}/android/play-store/gradle-wrapper.properties" \ + "${QT_ANDROID_DIR}/src/3rdparty/gradle/gradle/wrapper/gradle-wrapper.properties" + cp "${PROJECT_DIR}/android/play-store/gradlew" \ + "${QT_ANDROID_DIR}/src/3rdparty/gradle/gradlew" + chmod +x "${QT_ANDROID_DIR}/src/3rdparty/gradle/gradlew" + fi + build_dir="$(absolute_path "$build_dir")" pushd "${build_dir}" > /dev/null "${QT_QMAKE}" "${PROJECT_DIR}/Jamulus.pro" -spec android-clang "${qmake_config[@]}" \ - ANDROID_ABIS="${TARGET_ARCHS}" ANDROID_TARGET_SDK_VERSION=30 + ANDROID_ABIS="${TARGET_ARCHS}" ANDROID_TARGET_SDK_VERSION="${ANDROID_PLATFORM#android-}" "${ANDROID_NDK_MAKE}" -j "$MAKE_JOBS" "${ANDROID_NDK_MAKE}" INSTALL_ROOT="${build_dir}" install @@ -569,7 +630,8 @@ qmake5_qmake_make() { package_args+=(--sign "${ANDROID_KEYSTORE_FILE}" "${JAMULUS_ANDROID_KEY_ALIAS}" --storepass "${JAMULUS_ANDROID_KEYSTORE_PASSWORD}") [[ -n "${JAMULUS_ANDROID_KEY_PASSWORD:-}" ]] && package_args+=(--keypass "${JAMULUS_ANDROID_KEY_PASSWORD}") fi - "${QT_ANDROIDDEPLOYQT}" --verbose --input android-Jamulus-deployment-settings.json --output "${build_dir}" "${package_args[@]}" + "${QT_ANDROIDDEPLOYQT}" --verbose --input android-Jamulus-deployment-settings.json \ + --output "${build_dir}" "${package_args[@]}" popd > /dev/null } @@ -655,6 +717,7 @@ build_app() { if [[ "$build_mode" == release ]]; then package_args+=(--release) fi + [[ "$PACKAGE_FORMAT" == aab ]] && package_args+=(--aab) if [[ "$build_mode" == release && -n "${ANDROID_KEYSTORE_FILE:-}" ]]; then local detected_keystore_type detected_keystore_type="$(keystore_type "${ANDROID_KEYSTORE_FILE}" "${JAMULUS_ANDROID_KEYSTORE_PASSWORD}")" || detected_keystore_type="unknown" @@ -667,7 +730,7 @@ build_app() { fi fi - echo "Android packaging: format=APK platform=${ANDROID_PLATFORM}" + echo "Android packaging: format=${PACKAGE_FORMAT^^} platform=${ANDROID_PLATFORM}" # Diagnostic environment - non-secret variables only echo "Android environment:" @@ -705,14 +768,18 @@ pass_artifact_to_job() { for build_mode in $BUILD_MODES; do if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then - artifact="jamulus_${JAMULUS_BUILD_VERSION}_android_${build_mode}${ARTIFACT_SUFFIX}.apk" + artifact="jamulus_${JAMULUS_BUILD_VERSION}_android_${build_mode}${ARTIFACT_SUFFIX}.${PACKAGE_FORMAT}" if [[ "$build_mode" == debug ]]; then package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-debug.apk' -print -quit)" + elif [[ "$PACKAGE_FORMAT" == aab ]]; then + # release AAB files are produced without a "-signed" suffix; locate any .aab file + package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name "*-release.aab" -print -quit)" else - package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name '*-signed.apk' -print -quit)" + # release APK files are signed and have a "-signed" suffix + package_path="$(find "${BUILD_ROOT}/${build_mode}/build/outputs" -type f -name "*-release-signed.apk" -print -quit)" fi [[ -n "$package_path" ]] || { - echo "No Android APK was produced for ${build_mode}" >&2 + echo "No Android ${PACKAGE_FORMAT^^} was produced for ${build_mode}" >&2 exit 1 } mv "$package_path" "${DEPLOY_DIR}/${artifact}" @@ -753,6 +820,7 @@ case "${1:-}" in ;; build) validate_build_mode + validate_package_format validate_android_toolchain validate_signing for build_mode in $BUILD_MODES; do @@ -762,6 +830,7 @@ case "${1:-}" in done ;; get-artifacts) + validate_package_format pass_artifact_to_job ;; *) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 33d64bef23..c751932c21 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -15,6 +15,10 @@ # for every tag that starts with 'r' and does not have any suffix: # - do CodeQl while building for every platform # - publish the created binaries/packs only as artifacts/appendix as a release +# Android release builds are signed when the ANDROID_* signing secrets are all set. +# A manual run with android_play_store_upload builds only the Qt 5 release .aab (instead of the +# .apk and all other targets) and uploads it to Google Play (the run fails early if prerequisites are missing) +# (see publish_android_play_store); the release is sent to the internal testing track. on: workflow_dispatch: @@ -22,6 +26,9 @@ on: build_all_targets: type: boolean description: 'Build all targets (instead of just the main platforms)' + android_play_store_upload: + type: boolean + description: 'Android: build a Qt 5 release .aab and upload it to Google Play (needs release signing and Play secrets/variables)' push: tags: - 'r*' @@ -70,6 +77,8 @@ jobs: tag_name: ${{ steps.get-build-vars.outputs.RELEASE_TAG }} build_version: ${{ steps.get-build-vars.outputs.BUILD_VERSION }} build_all_targets: ${{ steps.decide-build-targets.outputs.build_all_targets }} + android_signing_ready: ${{ steps.android-readiness.outputs.signing_ready }} + android_play_store_upload: ${{ steps.android-readiness.outputs.play_store_upload }} env: release_changelog_path: ./.github_release_changelog.md # Set permissions. We need write permissions to content for creating/removing the release @@ -79,6 +88,28 @@ jobs: - name: Checkout code uses: actions/checkout@v7 + - name: Fail fast if a requested Google Play upload cannot be done + if: github.event_name == 'workflow_dispatch' && github.event.inputs.android_play_store_upload == 'true' + env: + HAVE_KEYSTORE: ${{ secrets.ANDROID_KEYSTORE != '' }} + HAVE_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS != '' }} + HAVE_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD != '' }} + HAVE_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD != '' }} + HAVE_GCP_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER != '' }} + HAVE_GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT_EMAIL != '' }} + run: | + missing="" + [[ "${HAVE_KEYSTORE}" == 'true' ]] || missing="${missing} secrets.ANDROID_KEYSTORE" + [[ "${HAVE_KEY_ALIAS}" == 'true' ]] || missing="${missing} secrets.ANDROID_KEY_ALIAS" + [[ "${HAVE_KEYSTORE_PASSWORD}" == 'true' ]] || missing="${missing} secrets.ANDROID_KEYSTORE_PASSWORD" + [[ "${HAVE_KEY_PASSWORD}" == 'true' ]] || missing="${missing} secrets.ANDROID_KEY_PASSWORD" + [[ "${HAVE_GCP_PROVIDER}" == 'true' ]] || missing="${missing} vars.GCP_WORKLOAD_IDENTITY_PROVIDER" + [[ "${HAVE_GCP_SERVICE_ACCOUNT}" == 'true' ]] || missing="${missing} vars.GCP_SERVICE_ACCOUNT_EMAIL" + if [[ -n "${missing}" ]]; then + echo "::error::Google Play upload requested but these are not set:${missing}" + exit 1 + fi + - name: Determine release version, type and prerelease variables run: ./.github/autobuild/get_build_vars.py id: get-build-vars @@ -110,6 +141,34 @@ jobs: body_path: ${{ env.release_changelog_path }} prerelease: ${{ steps.get-build-vars.outputs.IS_PRERELEASE }} + - name: Check Android signing and Google Play readiness + id: android-readiness + env: + HAVE_KEYSTORE: ${{ secrets.ANDROID_KEYSTORE != '' }} + HAVE_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS != '' }} + HAVE_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD != '' }} + HAVE_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD != '' }} + HAVE_GCP_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER != '' }} + HAVE_GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT_EMAIL != '' }} + INPUT_PLAY_STORE_UPLOAD: ${{ github.event.inputs.android_play_store_upload }} + run: | + set -eu + signing_ready=false + if [[ "${HAVE_KEYSTORE}" == 'true' && "${HAVE_KEY_ALIAS}" == 'true' && "${HAVE_KEYSTORE_PASSWORD}" == 'true' && "${HAVE_KEY_PASSWORD}" == 'true' ]]; then + signing_ready=true + fi + play_store_upload=false + if [[ "${GITHUB_EVENT_NAME}" == 'workflow_dispatch' && "${INPUT_PLAY_STORE_UPLOAD}" == 'true' ]]; then + if [[ "${signing_ready}" == 'true' && "${HAVE_GCP_PROVIDER}" == 'true' && "${HAVE_GCP_SERVICE_ACCOUNT}" == 'true' ]]; then + play_store_upload=true + else + echo "::error::Android Google Play upload requested but signing secrets (ANDROID_KEYSTORE, ANDROID_KEY_ALIAS, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_PASSWORD) or GCP variables (GCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT_EMAIL) are missing." + exit 1 + fi + fi + echo "signing_ready=${signing_ready}" >> $GITHUB_OUTPUT + echo "play_store_upload=${play_store_upload}" >> $GITHUB_OUTPUT + - name: Decide which targets to build for id: decide-build-targets env: @@ -206,6 +265,17 @@ jobs: # Jamulus.pro needs to count git history length for android versioning: checkout_fetch_depth: '0' + # Replaces the Qt 5 .apk build when requested (workflow_dispatch with android_play_store_upload); see the exclude rules below. + - config_name: Android Qt5 .aab (Google Play) + target_os: android + building_on_os: ubuntu-22.04 + base_command: JAVA_HOME= QT_DIR= ANDROID_NDK_ROOT= ANDROID_SDK_ROOT= JAMULUS_ANDROID_STREAM=qt5 JAMULUS_ANDROID_PLAY_STORE_BUILD=true ./.github/autobuild/android.sh + run_codeql: false + is_main_build_target: true + play_store_upload: true + dependency_cache_key: qt5-play-store + checkout_fetch_depth: '0' + - config_name: Android Qt6 ABI APK ZIPs (experimental) target_os: android building_on_os: ubuntu-22.04 @@ -286,12 +356,21 @@ jobs: # This injects the build_all_targets information into each matrix output: build_all_targets: - ${{ needs.create_release.outputs.build_all_targets }} + play_store_upload: + - ${{ needs.create_release.outputs.android_play_store_upload }} - # Exclude all non-main build targets if we are not building for all targets: exclude: + # Exclude all non-main build targets if we are not building for all targets: - build_all_targets: 'false' # This is based on a script output and is therefore a string config: is_main_build_target: null + # Exclusions: the Qt 5 .aab unless uploading to Google Play; everything except the .aab when uploading. + - play_store_upload: 'false' + config: + play_store_upload: true + - play_store_upload: 'true' + config: + play_store_upload: null runs-on: ${{ matrix.config.building_on_os }} steps: @@ -355,6 +434,16 @@ jobs: ~/android-ndk key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/autobuild/android-dependencies_qt5.sh') }}-${{ matrix.config.dependency_cache_key }} + - name: Cache Android Play Store dependencies + if: matrix.config.target_os == 'android' && matrix.config.dependency_cache_key == 'qt5-play-store' + uses: actions/cache@v6 + with: + path: | + ~/qt + ~/android-sdk + ~/android-ndk + key: ${{ matrix.config.target_os }}-${{ hashFiles('.github/autobuild/android-dependencies_qt5-play-store.sh', 'android/play-store/**') }}-${{ matrix.config.dependency_cache_key }} + - name: Cache Android Qt6 dependencies if: matrix.config.target_os == 'android' && matrix.config.dependency_cache_key == 'qt6' uses: actions/cache@v6 @@ -376,6 +465,22 @@ jobs: with: languages: 'cpp' + - name: Set Android Play Store version code + if: matrix.config.play_store_upload + run: | + set -eu + if ((GITHUB_RUN_ATTEMPT > 999)); then + echo "::error::GitHub run attempt exceeds the supported Android version-code range." + exit 1 + fi + version_code=$((GITHUB_RUN_NUMBER * 1000 + GITHUB_RUN_ATTEMPT)) + if ((version_code > 2100000000)); then + echo "::error::Generated Android version code exceeds Google's 2,100,000,000 limit." + exit 1 + fi + echo "JAMULUS_ANDROID_VERSION_CODE=${version_code}" >> "$GITHUB_ENV" + echo "Using Android version code ${version_code}" + - name: Build for ${{ matrix.config.config_name }} id: build run: ${{ matrix.config.base_command }} build @@ -388,6 +493,11 @@ jobs: # For every certificate, export it as base64 encoded string with `base64 -i certificate.p12` # Set the certificates based on the variables below JAMULUS_BUILD_VERSION: ${{ needs.create_release.outputs.build_version }} + # Android release signing: all-or-nothing, otherwise release builds use a generated debug key. + JAMULUS_ANDROID_KEYSTORE_BASE64: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEYSTORE || '' }} + JAMULUS_ANDROID_KEY_ALIAS: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEY_ALIAS || '' }} + JAMULUS_ANDROID_KEYSTORE_PASSWORD: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEYSTORE_PASSWORD || '' }} + JAMULUS_ANDROID_KEY_PASSWORD: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEY_PASSWORD || '' }} MACOS_CERTIFICATE_DEV_ID_APPLICATION: ${{ secrets.MACOS_CERT }} # Base64 encoded Developer ID Application certificate. See https://help.apple.com/xcode/mac/current/#/dev154b28f09 MACOS_CERTIFICATE_DEV_ID_APPLICATION_PWD: ${{ secrets.MACOS_CERT_PWD }} # Password protecting secrets.MACOS_CERTIFICATE_DEV_ID_APPLICATION MACOS_CERTIFICATE_DEV_ID_APPLICATION_ID: ${{ secrets.MACOS_CERT_ID }} # Certificate ID of secrets.MACOS_CERTIFICATE_DEV_ID_APPLICATION. If unknown, import secrets.MACOS_CERT into keychain and get the hash via "security find-identity -v" @@ -452,7 +562,8 @@ jobs: ARTIFACT_PATH: deploy/${{ steps.get-artifacts.outputs.artifact_1 }} - name: Deploy Artifact 1 to Release - if: needs.create_release.outputs.publish_to_release == 'true' + if: needs.create_release.outputs.publish_to_release == 'true' && + !matrix.config.play_store_upload id: upload-release-asset1 run: > gh release upload "${{ needs.create_release.outputs.tag_name }}" "deploy/${{ steps.get-artifacts.outputs.artifact_1 }}" --clobber @@ -460,6 +571,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Deploy Artifact 2 to Release if: needs.create_release.outputs.publish_to_release == 'true' && + !matrix.config.play_store_upload && steps.get-artifacts.outputs.artifact_2 id: upload-release-asset2 run: > @@ -470,6 +582,46 @@ jobs: if: matrix.config.run_codeql uses: github/codeql-action/analyze@v4.39.3 + publish_android_play_store: + name: Upload Android Qt5 .aab to Google Play (if requested) + runs-on: ubuntu-22.04 + needs: [create_release, release_assets] + if: needs.create_release.outputs.android_play_store_upload == 'true' + permissions: + contents: write + id-token: write + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Download the Android .aab + uses: actions/download-artifact@v8 + with: + name: jamulus_${{ needs.create_release.outputs.build_version }}_android_release_qt5.aab + path: deploy + + - name: Select the release bundle + id: select-bundle + run: ./.github/autobuild/android-play-store.sh deploy play-store + + - name: Authenticate to Google Cloud + id: gcloud-auth + uses: google-github-actions/auth@v3 + with: + workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ vars.GCP_SERVICE_ACCOUNT_EMAIL }} + + - name: Upload to Google Play + id: upload + uses: r0adkll/upload-google-play@e738b9dd8f2476ea806d921b64aacd24f34515a5 # v1.1.5 + with: + serviceAccountJson: ${{ steps.gcloud-auth.outputs.credentials_file_path }} + packageName: app.jamulus.jamulus.pljones_test + releaseFiles: ${{ steps.select-bundle.outputs.release_file }} + releaseName: ${{ needs.create_release.outputs.build_version }} + tracks: internal + status: completed + create_deb_repo: name: Create files for .deb repository (if requested) runs-on: ubuntu-22.04 @@ -528,4 +680,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release upload "${{ needs.create_release.outputs.tag_name }}" "repo/InRelease" "repo/key.asc" "repo/Packages" "repo/Release" --clobber -R "${{ github.repository}}" - diff --git a/.gitignore b/.gitignore index 3689f782ab..dac33126c1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ Makefile.* .idea .vscode .cache +.gradle/ *.user *.user.* *.o @@ -64,3 +65,4 @@ jamulus_plugin_import.cpp **/*.log android-build_*.settings Copilot-Processing.md +/play-store/ diff --git a/COMPILING.md b/COMPILING.md index bf62991f3f..6cde6edaf0 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -192,20 +192,24 @@ If you want to build the installer, please run the `deploy_mac.sh` script: `./ma ## Android -Android builds are available in two independent streams: +Android builds are available in the following independent profiles: -| Stream | Qt | Package | Java | NDK | Build Tools | Compile / target SDK | +| Stream | Qt | Package | Java | NDK | Build Tools | Compile / target SDK | Android range | | ------ | -- | ------- | ---- | --- | ----------- | ------------------- | ------------------------- | | `qt5` | 5.15.2 | Multi-ABI APK | 8 | r21d (21.0.6113669) | 30.0.2 | Android 11 / API 30 | API 21-31 | -| `qt6` | 6.10.2 | One APK per ABI, ZIPped | 17 | r27d (27.3.13750724) | 36.0.0 | Android 16 / API 36 | +| `qt5-play-store` | 5.15.2 | Release AAB | 17 | r21d (21.0.6113669) | 36.0.0 | Android 16 / API 36 | API 21-31 | +| `qt6` | 6.10.2 | One APK per ABI, ZIPped | 17 | r27d (27.3.13750724) | 36.0.0 | Android 16 / API 36 | API 28-36 | -As of Jamulus 4.0.0, the Android package ID is `app.jamulus.jamulus`. -Prior installation using the former `com.github.jamulussoftware.jamulus` ID will not be upgraded in-place. -(Users must uninstall the former package before installing the new one, losing their settings). +Android builds from this branch use the package ID +`app.jamulus.jamulus.pljones_test` for the personal Google Play test app. +This differs from the team's `app.jamulus.jamulus` package ID and will install +as a separate app. The compile/target SDK is the SDK level used to build and target the app, not the full Android compatibility range supported by Qt: - Qt 5 targets API 30 within its Android 5.0-12 / API 21-31 range. +- The Qt 5 Play Store profile targets API 36; Qt 5's Android compatibility + range remains Android 5.0-12 / API 21-31. - Qt 6 targets API 36 within its Android 9-16 / API 28-36 range. - Install the Qt, Android SDK, NDK, and JDK versions for the selected stream. @@ -236,6 +240,12 @@ The wrapper loads `android-build_qt5.settings` or and ABI/mode subsets in the matching file. Inspect resolved values with `--print-env`. +The Play Store AAB build uses a separate API 36 toolchain profile. For a local +Play Store build, optionally create +`android-build_qt5-play-store.settings` from +`tools/android-build_qt5-play-store.settings.example`; this keeps its Java 17 +and SDK paths separate from the regular Qt 5 APK settings. + Build Qt 5 APKs, which are suitable for temporary or release side-loading: ```bash @@ -248,6 +258,34 @@ Build experimental Qt 6 APK ZIPs with: tools/android-build.sh --stream qt6 --log android-qt6.log ``` +### Signing and the Google Play attempt + +Release builds are signed when `JAMULUS_ANDROID_KEYSTORE` (a file) or +`JAMULUS_ANDROID_KEYSTORE_BASE64`, `JAMULUS_ANDROID_KEY_ALIAS`, +`JAMULUS_ANDROID_KEYSTORE_PASSWORD` and `JAMULUS_ANDROID_KEY_PASSWORD` are set; +otherwise a generated debug key is used. This applies to both streams. In +GitHub Actions the keystore and passwords come from the `ANDROID_KEYSTORE`, +`ANDROID_KEY_ALIAS`, `ANDROID_KEYSTORE_PASSWORD` and `ANDROID_KEY_PASSWORD` +secrets, used only when all four are present. + +Only on request, the Qt 5 stream can build a release Android App Bundle (`.aab`) +instead of an APK. The Play Store build uses a separate experimental API 36 +target and updated Gradle packaging files; the regular Qt 5 APK build remains +on API 30. A release keystore is required. + +```bash +tools/android-build.sh --stream qt5 build get-artifacts play-store +``` + +This writes `deploy/jamulus__android_release_qt5.aab` and copies it to +`play-store/`. The `autobuild.yml` workflow can build and upload the bundle to +the app's Internal testing track via Workload Identity Federation when started +manually with `android_play_store_upload` (repository variables +`GCP_WORKLOAD_IDENTITY_PROVIDER` and `GCP_SERVICE_ACCOUNT_EMAIL` are required, +as are the Android release-signing secrets). The workflow publishes a completed +release on the `qa` track and sets a unique Android version code from the +workflow run number and attempt. + ### Build options - Both streams default to all four ABIs and debug and release modes. Qt 5 @@ -291,7 +329,8 @@ tools/android-build.sh --stream qt6 --log android-qt6.log - Release builds use the normal positive Git revision count as their Android version code for non-development versions. Development builds default to version code `1`. Set `JAMULUS_ANDROID_VERSION_CODE` when a build needs an - explicit positive version code. + explicit positive version code. The Google Play autobuild sets a unique + version code from the workflow run number and attempt. - Release builds use supplied Android keystore credentials when configured; debug builds ignore them and use normal debug signing. Without a supplied key, release builds use a temporary debug key and are not suitable for diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 48b4a48a72..bfd64b5f03 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -46,7 +46,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . --> - + @@ -64,7 +64,7 @@ along with this program. If not, see . - + diff --git a/android/play-store/build.gradle b/android/play-store/build.gradle new file mode 100644 index 0000000000..be7b060bf7 --- /dev/null +++ b/android/play-store/build.gradle @@ -0,0 +1,72 @@ +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:8.10.0' + } +} + +repositories { + google() + mavenCentral() +} + +apply plugin: 'com.android.application' + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) +} + +android { + namespace 'app.jamulus.jamulus.pljones_test' + compileSdkVersion androidCompileSdkVersion.toInteger() + buildToolsVersion androidBuildToolsVersion + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java'] + aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl'] + res.srcDirs = [qt5AndroidDir + '/res', 'res'] + resources.srcDirs = ['resources'] + assets.srcDirs = ['assets'] + jniLibs.srcDirs = ['libs'] + } + } + + tasks.withType(JavaCompile) { + options.incremental = true + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + lint { + abortOnError false + } + + androidResources { + noCompress += 'rcc' + } + + packaging { + jniLibs { + useLegacyPackaging true + } + } + + buildFeatures { + aidl true + } + + defaultConfig { + resConfig 'en' + minSdkVersion qtMinSdkVersion + targetSdkVersion qtTargetSdkVersion + } +} diff --git a/android/play-store/gradle-wrapper.properties b/android/play-store/gradle-wrapper.properties new file mode 100644 index 0000000000..81aa1c0448 --- /dev/null +++ b/android/play-store/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/android/play-store/gradlew b/android/play-store/gradlew new file mode 100644 index 0000000000..88be71c5c6 --- /dev/null +++ b/android/play-store/gradlew @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +APP_HOME="$(cd "$(dirname "$0")" && pwd)" +sed -i '/^android\.bundle\.enableUncompressedNativeLibs=/d' "${APP_HOME}/gradle.properties" + +JAVA=java +if [[ -n "${JAVA_HOME:-}" ]]; then + JAVA="${JAVA_HOME}/bin/java" +fi +exec "${JAVA}" -classpath "${APP_HOME}/gradle/wrapper/gradle-wrapper.jar" \ + org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/qt6/AndroidManifest.xml b/android/qt6/AndroidManifest.xml index f489746dc0..431b09902f 100644 --- a/android/qt6/AndroidManifest.xml +++ b/android/qt6/AndroidManifest.xml @@ -18,7 +18,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --> diff --git a/tools/android-build.sh b/tools/android-build.sh index 3647a17e44..f0db333996 100755 --- a/tools/android-build.sh +++ b/tools/android-build.sh @@ -33,6 +33,7 @@ readonly SCRIPT_NAME PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" readonly PROJECT_DIR readonly ANDROID_SH="${PROJECT_DIR}/.github/autobuild/android.sh" +readonly ANDROID_PLAY_STORE_SH="${PROJECT_DIR}/.github/autobuild/android-play-store.sh" MANAGED_VARS=( JAVA_HOME @@ -49,7 +50,9 @@ MANAGED_VARS=( JAMULUS_ANDROID_QMAKE_CONFIG JAMULUS_ANDROID_MAKE_JOBS JAMULUS_ANDROID_STREAM + JAMULUS_ANDROID_PLAY_STORE_BUILD JAMULUS_ANDROID_ARTIFACT_SUFFIX + JAMULUS_ANDROID_PACKAGE_FORMAT JAMULUS_ANDROID_VERSION_CODE JAMULUS_ANDROID_BUILD_DIR JAMULUS_ANDROID_DEPLOY_DIR @@ -78,7 +81,11 @@ apply_local_defaults() { export QT_SELECT="${QT_SELECT:-${QT_VERSION}-android}" # android.sh derives QT_ANDROID_DIR itself as "${QT_DIR}/${QT_VERSION}/android" : "${QT_DIR:=/opt/Qt}" - : "${BUILD_MODES:=debug release}" + local default_build_modes="debug release" + if has_stage play-store; then + default_build_modes=release + fi + : "${BUILD_MODES:=${default_build_modes}}" : "${TARGET_ARCHS:=armeabi-v7a arm64-v8a x86 x86_64}" } @@ -163,7 +170,7 @@ run_distclean() { local generated_path - for generated_path in "$BUILD_ROOT" "$DEPLOY_DIR"; do + for generated_path in "$BUILD_ROOT" "$DEPLOY_DIR" "${PROJECT_DIR}/play-store"; do rm -rf -- "$generated_path" done @@ -180,6 +187,9 @@ run_stage() { setup | build | get-artifacts) run_logged "$ANDROID_SH" "$stage" ;; + play-store) + run_logged "$ANDROID_PLAY_STORE_SH" + ;; distclean) run_distclean ;; @@ -189,6 +199,15 @@ run_stage() { esac } +has_stage() { + local requested_stage="$1" + local stage + for stage in "${STAGES[@]}"; do + [[ "$stage" == "$requested_stage" ]] && return 0 + done + return 1 +} + resolve_settings_file() { local requested="$1" if [[ -n "$requested" ]]; then @@ -199,7 +218,11 @@ resolve_settings_file() { printf '%s' "$JAMULUS_ANDROID_SETTINGS" return fi - local default_settings_file="${PROJECT_DIR}/android-build_${JAMULUS_ANDROID_STREAM}.settings" + local settings_suffix="$JAMULUS_ANDROID_STREAM" + if has_stage play-store; then + settings_suffix="${settings_suffix}-play-store" + fi + local default_settings_file="${PROJECT_DIR}/android-build_${settings_suffix}.settings" if [[ -f "$default_settings_file" ]]; then printf '%s' "$default_settings_file" return @@ -218,20 +241,22 @@ Jamulus.pro (plus the git hash for development versions) unless already set. Stages: setup Install CI-style SDK/NDK/Qt under /opt (rarely needed locally) - distclean make distclean (if a Makefile exists) and remove Android build and deploy outputs + distclean make distclean (if a Makefile exists) and remove Android build, deploy and Play Store outputs build Build selected debug/release packages get-artifacts Rename packages into deploy/ + play-store Qt 5 only: copy the release App Bundle from deploy/ to play-store/ + (also selects an App Bundle, release-only build; needs a release keystore) all distclean, build, and get-artifacts (default) Options: -h, --help Show this help - --settings FILE Override file (default: android-build_qtVERSION.settings if present) + --settings FILE Override file (default: stream settings; Play Store uses its own profile) --stream STREAM Select the Qt 5 or Qt 6 build (default: qt5) --log FILE Also write combined stdout/stderr to FILE --print-env Print the resolved environment and exit --build-modes "MODES" Override BUILD_MODES (default: "debug release") --archs "ARCHS" Override TARGET_ARCHS (default: "armeabi-v7a arm64-v8a x86 x86_64") - --jobs JOBS Limit parallel compiler jobs (default: nproc) + --jobs JOBS Limit parallel compiler jobs (default: nproc) Precedence: command-line options > settings file > existing environment > documented local defaults. See the matching tools/android-build_qtVERSION.settings.example. @@ -292,7 +317,7 @@ while [[ $# -gt 0 ]]; do STAGES+=(distclean build get-artifacts) shift ;; - setup | distclean | build | get-artifacts) + setup | distclean | build | get-artifacts | play-store) STAGES+=("$1") shift ;; @@ -308,11 +333,18 @@ fi cd "$PROJECT_DIR" [[ -x "$ANDROID_SH" || -f "$ANDROID_SH" ]] || error "cannot find $ANDROID_SH" +[[ -x "$ANDROID_PLAY_STORE_SH" || -f "$ANDROID_PLAY_STORE_SH" ]] || + error "cannot find $ANDROID_PLAY_STORE_SH" JAMULUS_ANDROID_STREAM="${OPTION_STREAM:-${JAMULUS_ANDROID_STREAM:-qt5}}" [[ "$JAMULUS_ANDROID_STREAM" == qt5 || "$JAMULUS_ANDROID_STREAM" == qt6 ]] || error "unsupported Android build stream: $JAMULUS_ANDROID_STREAM" -ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_${JAMULUS_ANDROID_STREAM}.sh" +if has_stage play-store; then + [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]] || error "the play-store stage requires --stream qt5" + ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_qt5-play-store.sh" +else + ANDROID_DEPENDENCIES="${PROJECT_DIR}/.github/autobuild/android-dependencies_${JAMULUS_ANDROID_STREAM}.sh" +fi EXPLICIT_COMMANDLINETOOLS_VERSION="${COMMANDLINETOOLS_VERSION:-}" EXPLICIT_ANDROID_NDK_VERSION="${ANDROID_NDK_VERSION:-}" EXPLICIT_ANDROID_PLATFORM="${ANDROID_PLATFORM:-}" @@ -333,6 +365,10 @@ load_settings_file "$(resolve_settings_file "$SETTINGS_FILE")" [[ -n "$OPTION_BUILD_MODES" ]] && BUILD_MODES="$OPTION_BUILD_MODES" [[ -n "$OPTION_TARGET_ARCHS" ]] && TARGET_ARCHS="$OPTION_TARGET_ARCHS" [[ -n "$OPTION_MAKE_JOBS" ]] && export JAMULUS_ANDROID_MAKE_JOBS="$OPTION_MAKE_JOBS" +if has_stage play-store; then + # shellcheck disable=SC2034 + JAMULUS_ANDROID_PLAY_STORE_BUILD=true +fi apply_local_defaults export_managed_env ensure_java_on_path diff --git a/tools/android-build_qt5-play-store.settings.example b/tools/android-build_qt5-play-store.settings.example new file mode 100644 index 0000000000..b28d256472 --- /dev/null +++ b/tools/android-build_qt5-play-store.settings.example @@ -0,0 +1,11 @@ +# Copy to android-build_qt5-play-store.settings in the repository root +# (gitignored), or pass --settings /path/to/file. Adjust paths for your system. + +# JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 +# ANDROID_SDK_ROOT=/opt/android-sdk +# ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk/21.0.6113669 +# QT_DIR=/opt/Qt +# QT_VERSION=5.15.2 + +# Add release signing values to this ignored file or provide them in the +# environment; never commit keystores or passwords. From d59cac9f665ba1452776abfa096f071b68306426 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 22 Nov 2026 21:01:02 +0000 Subject: [PATCH 5/5] Move to official packaging by default Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/autobuild/android-output-paths.sh | 4 +- .github/autobuild/android-package-default.sh | 42 ++ .github/autobuild/android.sh | 131 ++++-- .github/workflows/autobuild.yml | 38 +- COMPILING.md | 95 ++--- android/AndroidManifest.xml | 2 +- android/README.md | 403 +++++++++++++++++++ android/play-store/build.gradle | 2 +- android/qt6/AndroidManifest.xml | 2 +- tools/android-build.sh | 26 +- tools/android-build_qt5.settings.example | 11 +- tools/android-build_qt6.settings.example | 11 +- 12 files changed, 654 insertions(+), 113 deletions(-) create mode 100644 .github/autobuild/android-package-default.sh create mode 100644 android/README.md diff --git a/.github/autobuild/android-output-paths.sh b/.github/autobuild/android-output-paths.sh index 23fce5a4dd..818f9961f1 100644 --- a/.github/autobuild/android-output-paths.sh +++ b/.github/autobuild/android-output-paths.sh @@ -76,13 +76,13 @@ validate_android_output_paths() { exit 1 fi - for signing_path in "${JAMULUS_ANDROID_KEYSTORE:-}" "${JAMULUS_ANDROID_DEBUG_KEYSTORE:-}"; do + for signing_path in "${JAMULUS_ANDROID_KEYSTORE:-}" "${JAMULUS_ANDROID_DEV_KEYSTORE:-}" "${JAMULUS_ANDROID_DEBUG_KEYSTORE:-}"; do [[ -n "$signing_path" ]] || continue canonical_path="$(absolute_path "$signing_path")" || { echo "Failed to resolve Android signing file path: $signing_path" >&2 exit 1 } - for output_path in "${output_paths[@]}" "${LEGACY_ANDROID_OUTPUTS[@]}"; do + for output_path in "${output_paths[@]}" "${LEGACY_ANDROID_OUTPUTS[@]}" "${PROJECT_DIR}/play-store" "${PROJECT_DIR}/android/play-store/build" "${PROJECT_DIR}/android/play-store/.gradle"; do if path_is_within "$canonical_path" "$output_path"; then echo "Android signing file must not be inside a generated output path: $signing_path" >&2 exit 1 diff --git a/.github/autobuild/android-package-default.sh b/.github/autobuild/android-package-default.sh new file mode 100644 index 0000000000..51a7cbeb4f --- /dev/null +++ b/.github/autobuild/android-package-default.sh @@ -0,0 +1,42 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2026 +# +# Author(s): +# Peter L Jones +# The Jamulus Development Team +# +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +# Sourced by .github/workflows/autobuild.yml and tools/android-build.sh so +# both derive the same default Android application ID. + +# Lower-cases one segment, replaces characters invalid in a Java package +# segment with "_" and prefixes "x" when it does not start with a letter. +android_package_name_segment() { + local s + s="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" + s="${s//[^a-z0-9_]/_}" + [[ "$s" =~ ^[a-z] ]] || s="x${s}" + printf '%s' "$s" +} + +# Usage: android_default_package_name OWNER REPO +android_default_package_name() { + printf 'app.%s.%s' "$(android_package_name_segment "$1")" "$(android_package_name_segment "$2")" +} diff --git a/.github/autobuild/android.sh b/.github/autobuild/android.sh index 0bee53d8b3..2e5f41b73c 100755 --- a/.github/autobuild/android.sh +++ b/.github/autobuild/android.sh @@ -429,6 +429,14 @@ validate_package_format() { esac } +validate_package_name() { + if [[ -n "${JAMULUS_ANDROID_PACKAGE_NAME:-}" ]] && + [[ ! "$JAMULUS_ANDROID_PACKAGE_NAME" =~ ^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$ ]]; then + echo "Invalid Android package name: ${JAMULUS_ANDROID_PACKAGE_NAME}" >&2 + exit 1 + fi +} + validate_android_toolchain() { [[ -f "${ANDROID_NDK_ROOT}/source.properties" ]] || { echo "Selected Android NDK is not installed: ${ANDROID_NDK_ROOT}" >&2 @@ -448,33 +456,34 @@ validate_android_toolchain() { } validate_signing() { - local signing_setting + local build_mode - [[ " $BUILD_MODES " == *" release "* ]] || return 0 - # A bundle for store upload must never fall back to the generated debug key. + validate_android_output_paths + for build_mode in $BUILD_MODES; do + [[ "$build_mode" == release ]] && break + done + [[ "${build_mode:-}" == release ]] || return 0 + [[ -z "${JAMULUS_ANDROID_DEBUG_KEYSTORE:-}" ]] || { + echo "JAMULUS_ANDROID_DEBUG_KEYSTORE has been renamed to JAMULUS_ANDROID_DEV_KEYSTORE" >&2 + exit 1 + } [[ "$PACKAGE_FORMAT" != aab || -n "${JAMULUS_ANDROID_KEYSTORE:-}${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] || { echo "An Android App Bundle requires a release keystore" >&2 exit 1 } - [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}" ]] && echo "No Android keystore file specified" >&2 - [[ -z "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] && echo "No Android keystore base64 specified" >&2 - [[ -z "${JAMULUS_ANDROID_KEY_ALIAS:-}" ]] && echo "No Android keystore alias specified" >&2 - [[ -z "${JAMULUS_ANDROID_KEYSTORE_PASSWORD:-}" ]] && echo "No Android keystore password specified" >&2 - [[ -z "${JAMULUS_ANDROID_KEY_PASSWORD:-}" ]] && echo "No Android key password specified" >&2 - [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}" || -z "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] || { echo "Set only one of JAMULUS_ANDROID_KEYSTORE and JAMULUS_ANDROID_KEYSTORE_BASE64" >&2 exit 1 } - for signing_setting in JAMULUS_ANDROID_KEYSTORE JAMULUS_ANDROID_KEYSTORE_BASE64 \ - JAMULUS_ANDROID_KEY_ALIAS \ - JAMULUS_ANDROID_KEYSTORE_PASSWORD JAMULUS_ANDROID_KEY_PASSWORD; do - [[ -z "${!signing_setting:-}" || -n "${JAMULUS_ANDROID_KEYSTORE:-}" || - -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]] || { - echo "$signing_setting requires an Android keystore" >&2 + if [[ -n "${JAMULUS_ANDROID_DEV_KEYSTORE:-}" ]]; then + [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}${JAMULUS_ANDROID_KEYSTORE_BASE64:-}${JAMULUS_ANDROID_KEY_ALIAS:-}${JAMULUS_ANDROID_KEYSTORE_PASSWORD:-}${JAMULUS_ANDROID_KEY_PASSWORD:-}" ]] || { + echo "JAMULUS_ANDROID_DEV_KEYSTORE cannot be combined with release signing credentials" >&2 exit 1 } - done + elif [[ -z "${JAMULUS_ANDROID_KEYSTORE:-}${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then + echo "A release build requires JAMULUS_ANDROID_DEV_KEYSTORE or release keystore credentials" >&2 + exit 1 + fi if [[ -n "${JAMULUS_ANDROID_KEYSTORE:-}" || -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then [[ -n "${JAMULUS_ANDROID_KEY_ALIAS:-}" ]] || { echo "JAMULUS_ANDROID_KEY_ALIAS is required with a keystore" >&2 @@ -486,9 +495,10 @@ validate_signing() { } fi - validate_android_output_paths } +ANDROID_KEYSTORE_CLEANUP_FILE="" + cleanup_signing_for_mode() { if [[ -n "${ANDROID_KEYSTORE_CLEANUP_FILE:-}" ]]; then rm -f -- "$ANDROID_KEYSTORE_CLEANUP_FILE" @@ -505,8 +515,8 @@ prepare_signing_for_mode() { if [[ -n "${JAMULUS_ANDROID_KEYSTORE:-}" || -n "${JAMULUS_ANDROID_KEYSTORE_BASE64:-}" ]]; then prepare_keystore - elif [[ " $BUILD_MODES " == *" release "* ]]; then - prepare_debug_keystore + else + prepare_dev_keystore fi } @@ -525,7 +535,8 @@ prepare_keystore() { echo "Failed to create temporary Android keystore file" >&2 exit 1 fi - trap 'rm -f -- "$ANDROID_KEYSTORE_FILE"' EXIT + ANDROID_KEYSTORE_CLEANUP_FILE="$ANDROID_KEYSTORE_FILE" + trap cleanup_signing_for_mode EXIT local original_umask original_umask="$(umask)" umask 077 @@ -539,38 +550,28 @@ prepare_keystore() { fi } -prepare_debug_keystore() { - local debug_keystore="${JAMULUS_ANDROID_DEBUG_KEYSTORE:-}" - +prepare_dev_keystore() { JAMULUS_ANDROID_KEYSTORE_PASSWORD="android" JAMULUS_ANDROID_KEY_ALIAS="androiddebugkey" JAMULUS_ANDROID_KEY_PASSWORD="android" - if [[ -n "$debug_keystore" ]]; then - ANDROID_KEYSTORE_FILE="$(absolute_path "$debug_keystore")" - if [[ -e "$ANDROID_KEYSTORE_FILE" || -L "$ANDROID_KEYSTORE_FILE" ]]; then - if [[ -f "$ANDROID_KEYSTORE_FILE" && -r "$ANDROID_KEYSTORE_FILE" ]] && - keytool -list -keystore "$ANDROID_KEYSTORE_FILE" \ - -storepass "$JAMULUS_ANDROID_KEYSTORE_PASSWORD" \ - -alias "$JAMULUS_ANDROID_KEY_ALIAS" > /dev/null 2>&1; then - return - else - echo "Invalid Android debug keystore: $ANDROID_KEYSTORE_FILE" >&2 - exit 1 - fi + ANDROID_KEYSTORE_FILE="$(absolute_path "$JAMULUS_ANDROID_DEV_KEYSTORE")" + if [[ -e "$ANDROID_KEYSTORE_FILE" || -L "$ANDROID_KEYSTORE_FILE" ]]; then + if [[ -f "$ANDROID_KEYSTORE_FILE" && -r "$ANDROID_KEYSTORE_FILE" ]] && + keytool -list -keystore "$ANDROID_KEYSTORE_FILE" \ + -storepass "$JAMULUS_ANDROID_KEYSTORE_PASSWORD" \ + -alias "$JAMULUS_ANDROID_KEY_ALIAS" > /dev/null 2>&1; then + return else - mkdir -p "$(dirname "${ANDROID_KEYSTORE_FILE}")" - fi - else - if ! ANDROID_KEYSTORE_TEMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/jamulus-android-debug-signing.XXXXXX")"; then - echo "Failed to create temporary Android debug keystore" >&2 + echo "Invalid Android development keystore: $ANDROID_KEYSTORE_FILE" >&2 exit 1 fi - ANDROID_KEYSTORE_FILE="${ANDROID_KEYSTORE_TEMP_DIR}/debug.jks" - trap 'rm -rf -- "$ANDROID_KEYSTORE_TEMP_DIR"' EXIT fi mkdir -p "$(dirname "$ANDROID_KEYSTORE_FILE")" + local original_umask + original_umask="$(umask)" + umask 077 keytool -genkeypair \ -keystore "$ANDROID_KEYSTORE_FILE" \ -storepass "$JAMULUS_ANDROID_KEYSTORE_PASSWORD" \ @@ -580,6 +581,7 @@ prepare_debug_keystore() { -keysize 2048 \ -validity 10000 \ -dname "CN=Android Debug,O=Android,C=US" + umask "$original_umask" chmod 600 "$ANDROID_KEYSTORE_FILE" } @@ -621,7 +623,8 @@ qmake5_qmake_make() { build_dir="$(absolute_path "$build_dir")" pushd "${build_dir}" > /dev/null "${QT_QMAKE}" "${PROJECT_DIR}/Jamulus.pro" -spec android-clang "${qmake_config[@]}" \ - ANDROID_ABIS="${TARGET_ARCHS}" ANDROID_TARGET_SDK_VERSION="${ANDROID_PLATFORM#android-}" + ANDROID_ABIS="${TARGET_ARCHS}" ANDROID_TARGET_SDK_VERSION="${ANDROID_PLATFORM#android-}" \ + "${package_source_override[@]}" "${ANDROID_NDK_MAKE}" -j "$MAKE_JOBS" "${ANDROID_NDK_MAKE}" INSTALL_ROOT="${build_dir}" install @@ -673,7 +676,8 @@ qmake6_qmake_make() { mkdir -p "$arch_build_dir" pushd "$arch_build_dir" > /dev/null "$qmake6_qmake" "${PROJECT_DIR}/Jamulus.pro" -spec android-clang "${qmake_config[@]}" \ - ANDROID_ABIS="${target_arch}" ANDROID_TARGET_SDK_VERSION="${ANDROID_PLATFORM#android-}" + ANDROID_ABIS="${target_arch}" ANDROID_TARGET_SDK_VERSION="${ANDROID_PLATFORM#android-}" \ + "${package_source_override[@]}" "${ANDROID_NDK_MAKE}" -j "$MAKE_JOBS" "${ANDROID_NDK_MAKE}" INSTALL_ROOT="${arch_build_dir}" install @@ -741,6 +745,44 @@ build_app() { rm -rf "${build_dir}" mkdir -p "${build_dir}" + local -a package_source_override=() + local gradle_template="${QT_ANDROID_DIR}/src/android/templates/build.gradle" + if [[ "$PACKAGE_FORMAT" == aab && "$JAMULUS_ANDROID_PLAY_STORE_BUILD" == true ]]; then + gradle_template="${PROJECT_DIR}/android/play-store/build.gradle" + fi + local static_namespace="^[[:space:]]*namespace[[:space:]]+['\"][^'\"]+['\"]" + local package_name="${JAMULUS_ANDROID_PACKAGE_NAME:-}" + [[ -n "$package_name" ]] || { + echo "JAMULUS_ANDROID_PACKAGE_NAME must be set to build the Android package" >&2 + exit 1 + } + # Debug APKs are signed with the development key, so they get their own ID to coexist with release installs. + [[ "$build_mode" == debug ]] && package_name+=".debug" + local package_source="${PROJECT_DIR}/android" + local source_entry + [[ "$JAMULUS_ANDROID_STREAM" == qt6 ]] && package_source+="/qt6" + mkdir -p "${build_dir}/package-source" + for source_entry in "${package_source}"/*; do + case "${source_entry##*/}" in + play-store | qt6 | README.md) continue ;; + esac + cp -RL "$source_entry" "${build_dir}/package-source/" + done + grep -Fq 'package="++JAMULUS_ANDROID_PACKAGE_NAME++"' "${build_dir}/package-source/AndroidManifest.xml" || { + echo "Android manifest package template was not found" >&2 + exit 1 + } + sed -i "s/package=\"++JAMULUS_ANDROID_PACKAGE_NAME++\"/package=\"${package_name}\"/" \ + "${build_dir}/package-source/AndroidManifest.xml" + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 && -f "$gradle_template" ]] && grep -Eq "$static_namespace" "$gradle_template"; then + sed -E "s|${static_namespace}| namespace '${package_name}'|" "$gradle_template" \ + > "${build_dir}/package-source/build.gradle" + elif [[ "$PACKAGE_FORMAT" == aab ]]; then + echo "Android Gradle namespace template was not found" >&2 + exit 1 + fi + package_source_override=(-after "ANDROID_PACKAGE_SOURCE_DIR=${build_dir}/package-source") + if [[ "$JAMULUS_ANDROID_STREAM" == qt5 ]]; then qmake5_qmake_make "$build_mode" "${build_dir}" package_args "${qmake_config[@]}" else @@ -821,6 +863,7 @@ case "${1:-}" in build) validate_build_mode validate_package_format + validate_package_name validate_android_toolchain validate_signing for build_mode in $BUILD_MODES; do diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index c751932c21..968af5d779 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -79,6 +79,7 @@ jobs: build_all_targets: ${{ steps.decide-build-targets.outputs.build_all_targets }} android_signing_ready: ${{ steps.android-readiness.outputs.signing_ready }} android_play_store_upload: ${{ steps.android-readiness.outputs.play_store_upload }} + android_package_name: ${{ steps.android-package-name.outputs.package_name }} env: release_changelog_path: ./.github_release_changelog.md # Set permissions. We need write permissions to content for creating/removing the release @@ -141,6 +142,21 @@ jobs: body_path: ${{ env.release_changelog_path }} prerelease: ${{ steps.get-build-vars.outputs.IS_PRERELEASE }} + - name: Select Android application ID + id: android-package-name + env: + REPO_FULL: ${{ github.repository }} + PACKAGE_NAME_VAR: ${{ vars.ANDROID_PACKAGE_NAME }} + run: | + source .github/autobuild/android-package-default.sh + if [[ -n "${PACKAGE_NAME_VAR}" ]]; then + package_name="${PACKAGE_NAME_VAR}" + else + package_name="$(android_default_package_name "${REPO_FULL%%/*}" "${REPO_FULL#*/}")" + fi + echo "package_name=${package_name}" >> $GITHUB_OUTPUT + echo "Android application ID: ${package_name}" + - name: Check Android signing and Google Play readiness id: android-readiness env: @@ -481,6 +497,23 @@ jobs: echo "JAMULUS_ANDROID_VERSION_CODE=${version_code}" >> "$GITHUB_ENV" echo "Using Android version code ${version_code}" + - name: Select Android build modes + if: matrix.config.target_os == 'android' + env: + SIGNING_READY: ${{ needs.create_release.outputs.android_signing_ready }} + PLAY_STORE_UPLOAD: ${{ matrix.config.play_store_upload }} + run: | + if [[ "${PLAY_STORE_UPLOAD}" == 'true' ]]; then + build_modes=release + elif [[ "${SIGNING_READY}" == 'true' ]]; then + build_modes='debug release' + else + build_modes=debug + echo "::notice::Android release build skipped: signing secrets are unavailable or incomplete." + fi + echo "BUILD_MODES=${build_modes}" >> "$GITHUB_ENV" + echo "Android build modes: ${build_modes}" + - name: Build for ${{ matrix.config.config_name }} id: build run: ${{ matrix.config.base_command }} build @@ -493,7 +526,8 @@ jobs: # For every certificate, export it as base64 encoded string with `base64 -i certificate.p12` # Set the certificates based on the variables below JAMULUS_BUILD_VERSION: ${{ needs.create_release.outputs.build_version }} - # Android release signing: all-or-nothing, otherwise release builds use a generated debug key. + JAMULUS_ANDROID_PACKAGE_NAME: ${{ needs.create_release.outputs.android_package_name }} + # Android release signing is all-or-nothing. JAMULUS_ANDROID_KEYSTORE_BASE64: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEYSTORE || '' }} JAMULUS_ANDROID_KEY_ALIAS: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEY_ALIAS || '' }} JAMULUS_ANDROID_KEYSTORE_PASSWORD: ${{ needs.create_release.outputs.android_signing_ready == 'true' && secrets.ANDROID_KEYSTORE_PASSWORD || '' }} @@ -616,7 +650,7 @@ jobs: uses: r0adkll/upload-google-play@e738b9dd8f2476ea806d921b64aacd24f34515a5 # v1.1.5 with: serviceAccountJson: ${{ steps.gcloud-auth.outputs.credentials_file_path }} - packageName: app.jamulus.jamulus.pljones_test + packageName: ${{ needs.create_release.outputs.android_package_name }} releaseFiles: ${{ steps.select-bundle.outputs.release_file }} releaseName: ${{ needs.create_release.outputs.build_version }} tracks: internal diff --git a/COMPILING.md b/COMPILING.md index 6cde6edaf0..409cf8ecdb 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -200,10 +200,11 @@ Android builds are available in the following independent profiles: | `qt5-play-store` | 5.15.2 | Release AAB | 17 | r21d (21.0.6113669) | 36.0.0 | Android 16 / API 36 | API 21-31 | | `qt6` | 6.10.2 | One APK per ABI, ZIPped | 17 | r27d (27.3.13750724) | 36.0.0 | Android 16 / API 36 | API 28-36 | -Android builds from this branch use the package ID -`app.jamulus.jamulus.pljones_test` for the personal Google Play test app. -This differs from the team's `app.jamulus.jamulus` package ID and will install -as a separate app. +Local builds take the package ID from `JAMULUS_ANDROID_PACKAGE_NAME` (environment +or settings file). If it is unset, `tools/android-build.sh` uses +`app..` from a GitHub `origin` remote, the same as the workflow, +and otherwise stops with an error. Different package IDs install as separate +apps. Debug builds append `.debug` to the ID. The compile/target SDK is the SDK level used to build and target the app, not the full Android compatibility range supported by Qt: @@ -235,16 +236,11 @@ cp tools/android-build_qt5.settings.example android-build_qt5.settings cp tools/android-build_qt6.settings.example android-build_qt6.settings ``` -The wrapper loads `android-build_qt5.settings` or -`android-build_qt6.settings` by default. Set machine-specific toolchain paths -and ABI/mode subsets in the matching file. Inspect resolved values with -`--print-env`. - -The Play Store AAB build uses a separate API 36 toolchain profile. For a local -Play Store build, optionally create -`android-build_qt5-play-store.settings` from -`tools/android-build_qt5-play-store.settings.example`; this keeps its Java 17 -and SDK paths separate from the regular Qt 5 APK settings. +The wrapper defaults to the `qt5` stream. For APK builds, it loads +`android-build_qt5.settings`; with `--stream qt6`, it loads +`android-build_qt6.settings` instead. The `play-store` stage selects a +separate Qt 5 settings file. Set machine-specific toolchain paths and ABI/mode +subsets in the matching file. Inspect resolved values with `--print-env`. Build Qt 5 APKs, which are suitable for temporary or release side-loading: @@ -258,37 +254,28 @@ Build experimental Qt 6 APK ZIPs with: tools/android-build.sh --stream qt6 --log android-qt6.log ``` -### Signing and the Google Play attempt - -Release builds are signed when `JAMULUS_ANDROID_KEYSTORE` (a file) or -`JAMULUS_ANDROID_KEYSTORE_BASE64`, `JAMULUS_ANDROID_KEY_ALIAS`, -`JAMULUS_ANDROID_KEYSTORE_PASSWORD` and `JAMULUS_ANDROID_KEY_PASSWORD` are set; -otherwise a generated debug key is used. This applies to both streams. In -GitHub Actions the keystore and passwords come from the `ANDROID_KEYSTORE`, -`ANDROID_KEY_ALIAS`, `ANDROID_KEYSTORE_PASSWORD` and `ANDROID_KEY_PASSWORD` -secrets, used only when all four are present. - -Only on request, the Qt 5 stream can build a release Android App Bundle (`.aab`) -instead of an APK. The Play Store build uses a separate experimental API 36 -target and updated Gradle packaging files; the regular Qt 5 APK build remains -on API 30. A release keystore is required. +### Signing and Google Play -```bash -tools/android-build.sh --stream qt5 build get-artifacts play-store -``` +Release builds require signing: use `JAMULUS_ANDROID_KEYSTORE` (a file) or +`JAMULUS_ANDROID_KEYSTORE_BASE64` with `JAMULUS_ANDROID_KEY_ALIAS` and +`JAMULUS_ANDROID_KEYSTORE_PASSWORD`; set `JAMULUS_ANDROID_KEY_PASSWORD` when +the key requires it. For local development release APKs, use +`JAMULUS_ANDROID_DEV_KEYSTORE` instead. A release build without a key fails. +Debug builds use normal debug signing. This applies to both streams. +Play Store bundles require a release keystore matching the app's registered +upload certificate. -This writes `deploy/jamulus__android_release_qt5.aab` and copies it to -`play-store/`. The `autobuild.yml` workflow can build and upload the bundle to -the app's Internal testing track via Workload Identity Federation when started -manually with `android_play_store_upload` (repository variables -`GCP_WORKLOAD_IDENTITY_PROVIDER` and `GCP_SERVICE_ACCOUNT_EMAIL` are required, -as are the Android release-signing secrets). The workflow publishes a completed -release on the `qa` track and sets a unique Android version code from the -workflow run number and attempt. +The Qt 5 Play profile builds an Android App Bundle (`.aab`). The GitHub workflow +can upload it to Google Play's internal testing track. A locally built AAB can +also be uploaded manually in Play Console; the local build script does not +upload it. For Play builds and deployment setup, see +[Android deployment](android/README.md). ### Build options -- Both streams default to all four ABIs and debug and release modes. Qt 5 +- Local APK builds default to all four ABIs and debug mode. Request release + with `--build-modes release` or `--build-modes "debug release"`, or set + `BUILD_MODES` in the settings file or environment. Qt 5 artifacts are multi-ABI APKs with the `_qt5.apk` suffix. Qt 6 builds a standalone APK for each ABI and exports one `_qt6.zip` per mode; each ZIP contains exactly the selected ABIs. Build outputs are under @@ -299,9 +286,10 @@ workflow run number and attempt. tools/android-build.sh distclean ``` - This removes `android-build/`, `deploy/`, and the known legacy qmake Android - output paths, but leaves similarly named files and unrelated untracked - files in the checkout alone. + This removes `android-build/`, `deploy/`, `play-store/`, + `android/play-store/build/`, `android/play-store/.gradle/`, and the known + legacy qmake Android output paths, but leaves similarly named files and + unrelated untracked files in the checkout alone. - To build only the release compilation variant, set `BUILD_MODES=release`. Select a subset of architectures with `TARGET_ARCHS`: @@ -320,21 +308,18 @@ workflow run number and attempt. Set `ANDROID_NDK_ROOT` or `QT_DIR` to use different installed toolchains. Set `ANDROID_PLATFORM` to select the Android SDK platform. `BUILD_MODES` and `TARGET_ARCHS` can also be set in the stream's settings file. -- Debug builds are packaged as debuggable APKs. Local release builds use a - temporary debug keystore by default; it is deleted after the build. Set - `JAMULUS_ANDROID_DEBUG_KEYSTORE` to retain and reuse a debug keystore. An - existing file must be a valid Android debug keystore; a missing file is - created and retained. This key is for local development only, not for - publishing releases. +- Debug builds are packaged as debuggable APKs using Gradle's debug signing. + For local release-variant testing, set `JAMULUS_ANDROID_DEV_KEYSTORE` to a + reusable development keystore path. An existing file must be a valid + Android debug keystore; a missing file is created and retained. Its + well-known credentials make it unsuitable for publishing. Use a different + `JAMULUS_ANDROID_PACKAGE_NAME` from the official release. Debug and + development-release APKs with the same ID cannot update each other unless + they are signed with the same key. - Release builds use the normal positive Git revision count as their Android version code for non-development versions. Development builds default to version code `1`. Set `JAMULUS_ANDROID_VERSION_CODE` when a build needs an - explicit positive version code. The Google Play autobuild sets a unique - version code from the workflow run number and attempt. -- Release builds use supplied Android keystore credentials when configured; - debug builds ignore them and use normal debug signing. Without a supplied - key, release builds use a temporary debug key and are not suitable for - updating a retained production installation. + explicit positive version code. - Qt 5 APKs can be installed directly with `adb`. Extract a Qt 6 ABI APK from its ZIP before installing it. diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index bfd64b5f03..7a8c2e2814 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -46,7 +46,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . --> - + diff --git a/android/README.md b/android/README.md new file mode 100644 index 0000000000..24a0848c6b --- /dev/null +++ b/android/README.md @@ -0,0 +1,403 @@ +# Android deployment + + + +Android builds are experimental. For toolchains and local build commands, see +[COMPILING.md](../COMPILING.md#android). This guide covers the identities and +access needed to distribute builds from a GitHub repository. Do not commit +keystores, passwords, or generated Google credentials. + +## What is distributed? + +The normal GitHub Auto-Build produces a Qt 5 multi-ABI debug APK and, when +signing is configured, a release APK. The experimental Qt 6 build produces +ZIPs containing one APK per ABI. Download the desired run artifact and, for +Qt 6, extract the APK for the device's ABI. +These APKs can be installed directly, for example with `adb install path/to.apk`. + +The separate, manually requested Play build produces a Qt 5 release Android App +Bundle (AAB). GitHub uploads that bundle to the **internal testing track** as a +completed release, not to production. When requested, the workflow builds only +the AAB, not the normal APKs or other targets. The local `play-store` stage +only copies the bundle into `play-store/`; it does not upload anything. + +For a local Play build, optionally copy +`tools/android-build_qt5-play-store.settings.example` to +`android-build_qt5-play-store.settings` and set the toolchain and release +signing values. This profile uses a separate API 36 toolchain from the regular +Qt 5 APK build. Then run: + +```bash +tools/android-build.sh --stream qt5 build get-artifacts play-store +``` + +This writes `deploy/jamulus__android_release_qt5.aab` and copies it to +`play-store/`. The release keystore must match the Play app's registered upload +certificate; AAB builds do not fall back to a debug key. Upload the resulting +AAB manually in Play Console to create a testing-track release, if not using +the GitHub workflow. + +**Internal testing** and **Internal App Sharing** are different Play features. +The current workflow does not upload to Internal App Sharing or produce its +download link. See [Testing with Play](#testing-with-play) for both paths. + +## Application identity and signing + +An Android application ID identifies the app; the signing certificate +authenticates its updates. Android generally accepts an update only when its +application ID and signing identity match the installed app. Keep the release +signing key stable and backed up securely: losing it can prevent updates to +side-loaded installations. + +The build scripts require a signing key for release APKs so that subsequent +releases can update existing installations and recipients can verify a +consistent publisher identity. Debug builds use Gradle's normal debug signing +regardless of release credentials. A development keystore can sign local +release-variant APKs, but its well-known credentials make it unsuitable for +publication. + +For Play, distinguish the **upload key**, which signs the submitted AAB, from +the **app signing key**, which Play uses to sign APKs delivered to devices. +They may be different. The current workflow uses the same configured keystore +for side-load release APKs and Play AAB uploads. That does **not** make a +side-loaded APK update-compatible with a Play-installed app if Play uses a +different app signing certificate. Plan the keys and compare certificate +fingerprints before promising cross-channel updates; Google's +[app signing guide](https://developer.android.com/studio/publish/app-signing) +describes the options and upload-key reset process. Internal App Sharing uses +yet another, Google-managed test certificate. + +Choose the application ID deliberately before the first Play upload: Play +fixes it for that app, and changing it creates a different app. The workflow +defaults to `app..` (lower-cased, invalid characters replaced by +`_`), so the official repository builds and uploads as +`app.jamulussoftware.jamulus`. Set the GitHub repository variable +`ANDROID_PACKAGE_NAME` to override it. Setting `JAMULUS_ANDROID_PACKAGE_NAME` +locally overrides the default. The checked-in templates contain the placeholder +`++JAMULUS_ANDROID_PACKAGE_NAME++`, which the scripts replace in a temporary copy +(a build fails if no ID is set). The scripts apply the ID to the generated Android manifest and Play Gradle namespace without +editing the checked-in templates; the workflow uses the same value for the Play +API. Debug APKs append `.debug` to the ID so they can be installed alongside a +release build. + +## GitHub settings + +In the repository, open **Settings > Secrets and variables > Actions** and add +the following repository secrets. Use the existing key for an established app; +creating a new key does not reproduce an existing signing identity. + +| Secret | Meaning | +| --- | --- | +| `ANDROID_KEYSTORE` | Base64 encoding of the binary release keystore, not a path or a certificate. | +| `ANDROID_KEY_ALIAS` | Alias of the private signing key in that keystore. | +| `ANDROID_KEYSTORE_PASSWORD` | Password for the keystore. | +| `ANDROID_KEY_PASSWORD` | Password for the private key. | + +All four are required by the GitHub workflow for release signing. If any is +missing, normal Android builds produce only debug artifacts and report that +the release was skipped; a requested Play upload fails early. With all four, +normal builds produce both debug and release artifacts. Verify the signing +result before distribution. + +### Create a new signing identity + +For a new app or signing identity, the following Linux example creates a +private directory outside the repository and a PKCS12 keystore containing an +RSA signing key and certificate. Use a new directory that does not already +exist. `keytool` prompts for a keystore password and certificate details; +choose a strong password. The validity is 10,000 days. See also the +[Android key-generation instructions](https://developer.android.com/studio/publish/app-signing#generate-key). + +```bash +mkdir -m 700 "$HOME/android-signing" +keytool -genkeypair \ + -keystore "$HOME/android-signing/upload.p12" \ + -storetype PKCS12 -alias release_upload \ + -keyalg RSA -keysize 4096 -validity 10000 +``` + +`release_upload` is the example key alias; choose another if appropriate and +use it consistently below. Avoid secret values that occur in the application +ID or other workflow outputs: GitHub may mask them and skip affected job +outputs. For the PKCS12 keystore created by this command, use the same password +for the key and keystore. Record the alias and SHA-256 certificate fingerprint +and back up the keystore and password separately, with restricted access. +This command displays the public certificate fingerprint and prompts for the +keystore password: + +```bash +keytool -list -v -keystore "$HOME/android-signing/upload.p12" -alias release_upload +``` + +To configure GitHub Actions, replace `OWNER/REPO` with the target repository +in the following commands. The first encodes the binary keystore and sends it +to GitHub without printing it; the second stores its alias: + +```bash +base64 -w 0 "$HOME/android-signing/upload.p12" | gh secret set ANDROID_KEYSTORE --repo OWNER/REPO +printf '%s' release_upload | gh secret set ANDROID_KEY_ALIAS --repo OWNER/REPO +``` + +Set the keystore and key passwords at the interactive prompts, using the same +password for both with the example keystore. Alternatively, use the GitHub UI. +Do not put passwords on the command line. + +```bash +gh secret set ANDROID_KEYSTORE_PASSWORD --repo OWNER/REPO +gh secret set ANDROID_KEY_PASSWORD --repo OWNER/REPO +``` + +### Repository variables + +Set these repository **variables**: + +| Variable | Meaning | +| --- | --- | +| `ANDROID_PACKAGE_NAME` | Application ID override for APKs and the Play bundle. Defaults to `app..` if unset (the official repository uses `app.jamulussoftware.jamulus`). | +| `GCP_WORKLOAD_IDENTITY_PROVIDER` | Full provider resource name: `projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL_ID/providers/PROVIDER_ID`. Required for Play. | +| `GCP_SERVICE_ACCOUNT_EMAIL` | Email of the Google Cloud service account granted access to the Play app. Required for Play. | + +`GITHUB_TOKEN` is supplied by GitHub, not configured as a repository secret. +The Play job also requests `id-token: write` for GitHub OIDC. Repository +variables and secrets must be available to the selected workflow run; fork +pull requests and repository or organization policies can restrict them. +Protect the branches and users allowed to run workflows that can access release +signing credentials or request a Play upload. + +### Local equivalents and build controls + +For local builds, put the signing values in an ignored settings file or export +them in the environment. The wrapper sources a settings file as shell code, so +only use a file you trust. It exports settings-file values to the build driver: + +| Local variable | Purpose | +| --- | --- | +| `JAMULUS_ANDROID_KEYSTORE` | Path to a readable release keystore; alternatively use the base64 variable below. | +| `JAMULUS_ANDROID_KEYSTORE_BASE64` | Base64-encoded keystore; mutually exclusive with the file path. | +| `JAMULUS_ANDROID_KEY_ALIAS` | Alias in the release keystore. | +| `JAMULUS_ANDROID_KEYSTORE_PASSWORD` | Release keystore password. | +| `JAMULUS_ANDROID_KEY_PASSWORD` | Release key password; pass it when the key requires one. The GitHub workflow requires it. | +| `JAMULUS_ANDROID_DEV_KEYSTORE` | Path to a reusable development-only keystore for release APKs. If missing, it is created and retained with Android debug-key credentials (`androiddebugkey` / `android`). An existing file must be a valid Android debug keystore. Do not combine with release signing credentials or use for publishing. | +| `JAMULUS_ANDROID_PACKAGE_NAME` | Optional application ID override; use the same ID as the intended Play app for Play builds. | +| `JAMULUS_ANDROID_VERSION_CODE` | Optional explicit Android version code. Use a valid positive code appropriate to the target app. | +| `JAMULUS_BUILD_VERSION` | Build/artifact version; the local wrapper otherwise derives it from `Jamulus.pro` and Git. | +| `JAMULUS_ANDROID_STREAM` | `qt5` or `qt6`; the wrapper's `--stream` selects it. | +| `JAMULUS_ANDROID_PLAY_STORE_BUILD` | Selects the Play profile when `true`; the wrapper sets it when the `play-store` stage is requested. | +| `JAMULUS_ANDROID_PACKAGE_FORMAT` | `apk` normally, `aab` for the Play profile; AAB requires Qt 5, Play mode and release-only builds. | +| `BUILD_MODES`, `TARGET_ARCHS` | Build variants and ABI list; the wrapper also accepts `--build-modes` and `--archs`. | +| `JAMULUS_ANDROID_QMAKE_CONFIG` | Optional space-separated qmake `CONFIG` values to add to each build. | +| `JAMULUS_ANDROID_ARTIFACT_SUFFIX` | Optional artifact filename suffix; keep the default for the Play bundle selector. | +| `JAMULUS_ANDROID_BUILD_DIR`, `JAMULUS_ANDROID_DEPLOY_DIR` | Optional build and artifact output directories. | +| `JAMULUS_ANDROID_SETTINGS` | Optional settings-file path when `--settings` is not supplied. | + +For example, add this to the selected settings file or export it in the +environment (a settings-file value overrides the environment): + +```bash +JAMULUS_ANDROID_QMAKE_CONFIG="disable_version_check nojsonrpc" +``` + +Each value is passed to qmake as `CONFIG+=`. See the +[compile time arguments](../COMPILING.md#compile-time-arguments) for options. +For GitHub builds, set `JAMULUS_ANDROID_QMAKE_CONFIG` in the build step's +`env` in [autobuild.yml](../.github/workflows/autobuild.yml); a repository +variable alone is not passed to the build. + +Toolchain paths and version overrides are described in +[COMPILING.md](../COMPILING.md#android) and the +[settings examples](../tools/). Avoid placing keystores inside generated +output directories. `--log` captures build output; treat logs as potentially +sensitive, especially when using verbose tools. + +Local APK builds default to debug mode. Request a release with +`--build-modes release` or `--build-modes "debug release"`, or set +`BUILD_MODES` explicitly in a settings file or the environment. The Play +profile defaults to release. When using a development key, choose an +application ID different from official releases. A debug APK and a +development-release APK with the same ID can update each other only if their +signing keys match. + +For Play uploads the workflow sets `JAMULUS_ANDROID_VERSION_CODE` to +`GITHUB_RUN_NUMBER * 1000 + GITHUB_RUN_ATTEMPT`, subject to its range checks. +Run numbers are scoped to a workflow in a repository: they do not ensure +monotonicity across repositories, other workflows, or manual uploads. Check the +existing Play version codes before moving publication to a new repository. +`JAMULUS_BUILD_VERSION` supplies the artifact and Play release name; it is not +the Android version code. + +## Google Cloud setup + +The workflow exchanges a GitHub OIDC token for short-lived credentials using +Workload Identity Federation (WIF), then impersonates a service account. It +does not need a downloaded service-account JSON key. An administrator needs +permission to enable APIs, create a service account, administer WIF pools and +providers, and change that service account's IAM policy. Google recommends a +dedicated project for pools and requires billing enabled; see the +[Google WIF guide](https://cloud.google.com/iam/docs/workload-identity-federation-with-deployment-pipelines) +for prerequisites and propagation delays. + +The examples below restrict access to one repository and the `main` branch. +Use the actual protected publication branch if different. Obtain numeric +repository and owner IDs, for example with +`gh api repos/OWNER/REPO --jq '[.id,.owner.id] | @tsv'`. Numeric IDs avoid +trusting a repository name that could later be reused. Restrict who may edit +the trusted branch and workflow: a workflow on that branch can request the +service account's identity. + +### Cloud Console + +1. Select or create a Cloud project and enable billing. Under **APIs & + Services > Library**, enable IAM, Cloud Resource Manager, IAM Service + Account Credentials, Security Token Service and Google Play Developer API. +2. Under **IAM & Admin > Service Accounts**, create a dedicated service + account. Record its email; no service-account key is needed. +3. Under **IAM & Admin > Workload Identity Federation**, create a pool and an + OIDC provider. Set issuer to `https://token.actions.githubusercontent.com/` + and use the default audience. Add these attribute mappings: + + ```text + google.subject=assertion.sub + attribute.repository_id=assertion.repository_id + attribute.repository_owner_id=assertion.repository_owner_id + attribute.ref=assertion.ref + ``` + +4. Set the provider condition below, substituting the numeric IDs and + publication branch: + + ```text + attribute.repository_id=='REPOSITORY_ID' && attribute.repository_owner_id=='OWNER_ID' && attribute.ref=='refs/heads/main' + ``` + +5. In the pool's **Grant access** flow, grant service-account impersonation + to identities matching `repository_id` and the numeric repository ID. + The binding must grant **Workload Identity User** + (`roles/iam.workloadIdentityUser`) on the service account. The provider + condition further limits the owner and branch. +6. Copy the full provider resource name, using the **project number**, and + the service-account email into the GitHub variables above. Give the + service account Play permissions as described below; Cloud IAM permissions + alone do not grant access to Play Console. + +### Equivalent `gcloud` commands + +Run these as an authorized administrator in Cloud Shell, or run +`gcloud auth login` first in a local shell. Replace all placeholder values. +These commands create new resources; reuse existing resources rather than +recreating them if appropriate. + +```bash +PROJECT_ID=YOUR_CLOUD_PROJECT_ID +REPOSITORY_ID=YOUR_NUMERIC_GITHUB_REPOSITORY_ID +OWNER_ID=YOUR_NUMERIC_GITHUB_OWNER_ID +POOL_ID=github-actions +PROVIDER_ID=github +SERVICE_ACCOUNT_ID=jamulus-play +BRANCH=main + +gcloud config set project "$PROJECT_ID" +gcloud services enable iam.googleapis.com cloudresourcemanager.googleapis.com \ + iamcredentials.googleapis.com sts.googleapis.com androidpublisher.googleapis.com +PROJECT_NUMBER="$(gcloud projects describe "$PROJECT_ID" --format='value(projectNumber)')" +SERVICE_ACCOUNT_EMAIL="${SERVICE_ACCOUNT_ID}@${PROJECT_ID}.iam.gserviceaccount.com" +gcloud iam service-accounts create "$SERVICE_ACCOUNT_ID" --display-name="Jamulus Play upload" +gcloud iam workload-identity-pools create "$POOL_ID" --location=global \ + --display-name="GitHub Actions" +gcloud iam workload-identity-pools providers create-oidc "$PROVIDER_ID" \ + --location=global --workload-identity-pool="$POOL_ID" \ + --issuer-uri="https://token.actions.githubusercontent.com/" \ + --attribute-mapping="google.subject=assertion.sub,attribute.repository_id=assertion.repository_id,attribute.repository_owner_id=assertion.repository_owner_id,attribute.ref=assertion.ref" \ + --attribute-condition="attribute.repository_id=='${REPOSITORY_ID}' && attribute.repository_owner_id=='${OWNER_ID}' && attribute.ref=='refs/heads/${BRANCH}'" +gcloud iam service-accounts add-iam-policy-binding "$SERVICE_ACCOUNT_EMAIL" \ + --role=roles/iam.workloadIdentityUser \ + --member="principalSet://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/${POOL_ID}/attribute.repository_id/${REPOSITORY_ID}" +printf 'GCP_WORKLOAD_IDENTITY_PROVIDER=projects/%s/locations/global/workloadIdentityPools/%s/providers/%s\n' \ + "$PROJECT_NUMBER" "$POOL_ID" "$PROVIDER_ID" +printf 'GCP_SERVICE_ACCOUNT_EMAIL=%s\n' "$SERVICE_ACCOUNT_EMAIL" +``` + +Only the two printed identifiers are GitHub variables, not secrets. The API +must be enabled in the service account's Cloud project. If the pool and +service account are in different projects, use the pool's project **number** +in the principal and provider name and the service account's own project in +its email and IAM operation. + +## Play Console setup + +1. In [Play Console](https://play.google.com/console), create or select the + app and complete the applicable account, app and testing prerequisites. + Choose the package ID before the first upload. If the app is new, upload an + appropriately signed AAB manually first and configure Play App Signing; + the upload action expects the app/package to exist already. +2. Under **Test and release > Setup > App signing**, record both the upload and + Play app-signing certificate fingerprints. The configured keystore must + contain the private key matching the registered **upload certificate**. + Separately compare the Play app-signing certificate with the certificate + of a side-loaded APK if updates across channels are required. +3. In **Users and permissions**, invite the Cloud service-account email and + grant access to the specific app, including **View app information + (read-only)** and **Release apps to testing tracks**. Add other permissions + only if needed. This is separate from the Cloud WIF impersonation binding. + See [Google Play Developer API setup](https://developers.google.com/android-publisher/getting_started). +4. Ensure the Play Console app's package ID matches the application ID the + workflow uses: `ANDROID_PACKAGE_NAME` if set, otherwise the default + `app..`. The AAB application ID and the Play Console app's + package ID must be identical. The GitHub WIF provider + must trust the actual repository and branch, and the service-account email + in GitHub must be the one invited to Play. + +## Testing with Play + +### Internal testing track (the current workflow) + +In **Test and release > Testing > Internal testing**, create/select an email +list, add testers, set a feedback contact and save. Share the opt-in link; +testers must opt in with an eligible Google account. See +[Google's internal testing instructions](https://support.google.com/googleplay/android-developer/answer/9845334). + +On the trusted branch, run **Actions > Auto-Build > Run workflow** and select +`android_play_store_upload`. Check the build artifact, signing identity, +upload job and Play Console release status. A completed internal-track release +can become available to opted-in testers; it is not merely an uncommitted +draft. First-time setup, review, tester access and propagation may delay +availability. The workflow does not automatically publish to production. + +### Internal App Sharing (manual alternative) + +This is not the internal testing track. In the app's **Test and release > +Setup > Internal app sharing**, configure authorized uploader and tester email +lists, or allow anyone with the link as appropriate. An authorized uploader +uses the [Internal App Sharing upload page](https://play.google.com/console/internal-app-sharing/) +to upload an APK or AAB and shares the resulting link. The local Play build +can supply the AAB, but neither the local script nor the current workflow +performs this upload. + +On the tester's device, open Play Store settings, tap the Play Store version +seven times under **About**, then enable **Internal app sharing**. Open the +sharing link with the authorized account. Google re-signs these artifacts with +an Internal App Sharing test key; they generally cannot update installs signed +with another certificate. Version codes can be reused here; links expire +after 60 days and allow up to 100 downloads each. See +[Google's Internal App Sharing guide](https://support.google.com/googleplay/android-developer/answer/9844679). + +## Troubleshooting + +- **Cannot exchange GitHub token:** check `id-token: write`, the provider name + and project number, issuer/audience, attribute mappings and conditions, + repository/owner IDs, branch, and the service-account WIF binding. New IAM + settings can take time to propagate. +- **Play API denied:** check that the Play Developer API is enabled and that + the exact service-account email has the required app-level Play permissions. + A successful Cloud authentication does not prove Play access. +- **Package or signing rejected:** compare `ANDROID_PACKAGE_NAME`, the + bundle's application ID and the Play app ID; compare the keystore's + certificate with Play's upload certificate. Do not confuse upload, Play + app-signing and Internal App Sharing certificates. +- **Version code rejected:** compare against all existing releases and other + publishers. GitHub run numbers are not globally coordinated. +- **Tester cannot install:** distinguish a track opt-in link from an Internal + App Sharing link, check the Google account and tester list, and allow time + for Play propagation. An incompatible installed signature requires + uninstalling the old app before installing the new one; uninstalling can + remove its local data. diff --git a/android/play-store/build.gradle b/android/play-store/build.gradle index be7b060bf7..899c636dae 100644 --- a/android/play-store/build.gradle +++ b/android/play-store/build.gradle @@ -21,7 +21,7 @@ dependencies { } android { - namespace 'app.jamulus.jamulus.pljones_test' + namespace '++JAMULUS_ANDROID_PACKAGE_NAME++' compileSdkVersion androidCompileSdkVersion.toInteger() buildToolsVersion androidBuildToolsVersion diff --git a/android/qt6/AndroidManifest.xml b/android/qt6/AndroidManifest.xml index 431b09902f..373327e514 100644 --- a/android/qt6/AndroidManifest.xml +++ b/android/qt6/AndroidManifest.xml @@ -18,7 +18,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --> diff --git a/tools/android-build.sh b/tools/android-build.sh index f0db333996..dae57ee492 100755 --- a/tools/android-build.sh +++ b/tools/android-build.sh @@ -53,6 +53,7 @@ MANAGED_VARS=( JAMULUS_ANDROID_PLAY_STORE_BUILD JAMULUS_ANDROID_ARTIFACT_SUFFIX JAMULUS_ANDROID_PACKAGE_FORMAT + JAMULUS_ANDROID_PACKAGE_NAME JAMULUS_ANDROID_VERSION_CODE JAMULUS_ANDROID_BUILD_DIR JAMULUS_ANDROID_DEPLOY_DIR @@ -81,7 +82,7 @@ apply_local_defaults() { export QT_SELECT="${QT_SELECT:-${QT_VERSION}-android}" # android.sh derives QT_ANDROID_DIR itself as "${QT_DIR}/${QT_VERSION}/android" : "${QT_DIR:=/opt/Qt}" - local default_build_modes="debug release" + local default_build_modes=debug if has_stage play-store; then default_build_modes=release fi @@ -103,6 +104,16 @@ load_settings_file() { set +a } +# Derives the default application ID from the origin remote's GitHub owner/repo. +default_package_name_from_origin() { + local url owner repo + url="$(git -C "$PROJECT_DIR" remote get-url origin 2> /dev/null)" || return 1 + [[ "$url" =~ github\.com[:/]+([^/:]+)/([^/]+)/?$ ]] || return 1 + owner="${BASH_REMATCH[1]}" + repo="${BASH_REMATCH[2]%.git}" + android_default_package_name "$owner" "$repo" +} + export_managed_env() { local var for var in "${MANAGED_VARS[@]}"; do @@ -170,7 +181,7 @@ run_distclean() { local generated_path - for generated_path in "$BUILD_ROOT" "$DEPLOY_DIR" "${PROJECT_DIR}/play-store"; do + for generated_path in "$BUILD_ROOT" "$DEPLOY_DIR" "${PROJECT_DIR}/play-store" "${PROJECT_DIR}/android/play-store/build" "${PROJECT_DIR}/android/play-store/.gradle"; do rm -rf -- "$generated_path" done @@ -254,11 +265,14 @@ Options: --stream STREAM Select the Qt 5 or Qt 6 build (default: qt5) --log FILE Also write combined stdout/stderr to FILE --print-env Print the resolved environment and exit - --build-modes "MODES" Override BUILD_MODES (default: "debug release") + --build-modes "MODES" Override BUILD_MODES (default: debug; Play Store: release) --archs "ARCHS" Override TARGET_ARCHS (default: "armeabi-v7a arm64-v8a x86 x86_64") --jobs JOBS Limit parallel compiler jobs (default: nproc) Precedence: command-line options > settings file > existing environment > documented local defaults. +JAMULUS_ANDROID_PACKAGE_NAME is required for build stages: it defaults to +app.. from a GitHub origin remote; otherwise set it in the +environment or the settings file. See the matching tools/android-build_qtVERSION.settings.example. EOF } @@ -362,6 +376,12 @@ source "$ANDROID_DEPENDENCIES" [[ -n "$EXPLICIT_ANDROID_JAVA_VERSION" ]] && ANDROID_JAVA_VERSION="$EXPLICIT_ANDROID_JAVA_VERSION" [[ -n "$EXPLICIT_QT_VERSION" ]] && QT_VERSION="$EXPLICIT_QT_VERSION" load_settings_file "$(resolve_settings_file "$SETTINGS_FILE")" +# shellcheck disable=SC1090 +source "${PROJECT_DIR}/.github/autobuild/android-package-default.sh" +if [[ -z "${JAMULUS_ANDROID_PACKAGE_NAME:-}" ]] && { has_stage build || has_stage play-store; }; then + JAMULUS_ANDROID_PACKAGE_NAME="$(default_package_name_from_origin)" || + error "JAMULUS_ANDROID_PACKAGE_NAME is not set and origin is not a GitHub remote; set it on the command line or in the settings file" +fi [[ -n "$OPTION_BUILD_MODES" ]] && BUILD_MODES="$OPTION_BUILD_MODES" [[ -n "$OPTION_TARGET_ARCHS" ]] && TARGET_ARCHS="$OPTION_TARGET_ARCHS" [[ -n "$OPTION_MAKE_JOBS" ]] && export JAMULUS_ANDROID_MAKE_JOBS="$OPTION_MAKE_JOBS" diff --git a/tools/android-build_qt5.settings.example b/tools/android-build_qt5.settings.example index 21ce47f893..b0e98de8ca 100644 --- a/tools/android-build_qt5.settings.example +++ b/tools/android-build_qt5.settings.example @@ -10,10 +10,17 @@ # QT_DIR=/opt/Qt # ANDROID_PLATFORM=android-30 -# Narrow these for faster local rebuilds: -BUILD_MODES=release +# Default build mode is debug. Release mode requires signing: +# BUILD_MODES=release TARGET_ARCHS=arm64-v8a +# Application ID for APKs. Required for build stages unless origin is a GitHub +# remote (then app.. is used). Uncomment and set to override. +# Use a distinct ID for development release APKs, and a persistent keystore +# outside generated output directories: +# JAMULUS_ANDROID_PACKAGE_NAME=app.example.jamulus +# JAMULUS_ANDROID_DEV_KEYSTORE=${HOME}/Jamulus/dev-signing.jks + # Optional qmake CONFIG values, space-separated: # JAMULUS_ANDROID_QMAKE_CONFIG="serveronly disable_version_check" diff --git a/tools/android-build_qt6.settings.example b/tools/android-build_qt6.settings.example index 5ffc5b0625..7709896a04 100644 --- a/tools/android-build_qt6.settings.example +++ b/tools/android-build_qt6.settings.example @@ -10,14 +10,21 @@ # QT_DIR=/opt/Qt # ANDROID_PLATFORM=android-36 -# Defaults to all four ABIs and both build modes. +# Defaults to all four ABIs and debug mode. Release mode requires signing: # BUILD_MODES=release TARGET_ARCHS=arm64-v8a +# Application ID for APKs. Required for build stages unless origin is a GitHub +# remote (then app.. is used). Uncomment and set to override. +# Use a distinct ID for development release APKs, and a persistent keystore +# outside generated output directories: +# JAMULUS_ANDROID_PACKAGE_NAME=app.example.jamulus +# JAMULUS_ANDROID_DEV_KEYSTORE=${HOME}/Jamulus/dev-signing.jks + # Optional qmake CONFIG values, space-separated: # JAMULUS_ANDROID_QMAKE_CONFIG="serveronly disable_version_check" -# Optional release signing (keep these outside the repository): +# Production release signing instead of the development keystore: # JAMULUS_ANDROID_KEYSTORE=${HOME}/Jamulus/jamulus-upload.jks # JAMULUS_ANDROID_KEY_ALIAS=jamulus # JAMULUS_ANDROID_KEYSTORE_PASSWORD=production-password