libretroshare/misc/Android/Dockerfile
Gioacchino Mazzurco ba90b27199
Fix Android build for ndk r29 on ubuntu 26.04
Drop armeabi-v7a and minapi16 (EOL), build arm64-v8a at API 21/24 only.

Toolchain:
- Replace make_standalone_toolchain.py with direct NDK toolchain copy
- Use NDK r29 compiler triple naming and llvm-ar/llvm-ranlib
- Add gentoo_disturl() for hash-based Gentoo mirror URLs

Dependencies:
- Add librnp (openssl backend) with json-c and sexpp support
- Add qemu-user for librnp cross-compilation feature detection
- Replace sqlcipher with plain sqlite (RS_SQLCIPHER=OFF)
- Switch rapidjson to git source for C++17 compatibility
- Bump bzip2, zlib, libpng, xapian, tiff, cimg, sqlite versions

CMake:
- Remove Android C++14 workaround (NDK r29 std::filesystem works)
- Refactor RS_RNPLIB to support inline, pre-built, and FetchContent
- Add CMAKE_POLICY_VERSION_MINIMUM for CMake 4.x compatibility

Dockerfile:
- Move to Ubuntu 26.04, python-is-python3
- Split COPY for layer caching of SDK and toolchain builds
2026-06-14 11:44:03 +02:00

95 lines
3.7 KiB
Docker

## To prepare an image suitable as base for Gitlab CI use
## image name must match gitlab repository name, you can play just with the tag
## the part after :
# export ANDROID_MIN_API_LEVEL=21
# export CI_IMAGE_NAME="registry.gitlab.com/retroshare/retroshare:android_aar_base_${ANDROID_MIN_API_LEVEL}"
# docker build --squash --tag "${CI_IMAGE_NAME}" --build-arg ANDROID_MIN_API_LEVEL=${ANDROID_MIN_API_LEVEL} --build-arg LIBRETROSHARE_SOURCE_VERSION="$(git describe --always)" --file misc/Android/Dockerfile .
## To fit GitlabCI shared runners as they are limited to 25GB disk size
## use --squash
## and set
## GRADLE_BUILD_TASK to bundleDebugAar or bundleReleaseAar
## JNI_NATIVE_LIBS_ARCHS to arm64-v8a
## To push it to gitlab CI registry you need first to login and the to push
# docker login registry.gitlab.com
# docker push ${CI_IMAGE_NAME}
## To easly extract artifacts and other files you are interested into from the
## image you can use a command similar to:
# docker cp $(docker create --rm ${CI_IMAGE_NAME}):/libretroshare-aar/* $HOME/
## see https://stackoverflow.com/a/59055906
FROM ubuntu:26.04
ENV DEBIAN_FRONTEND=noninteractive
ENV APT_UNAT="--assume-yes --quiet"
ENV APT_INSTALL="apt-get install --no-install-recommends $APT_UNAT"
RUN apt-get update $APT_UNAT && apt-get upgrade --show-upgraded $APT_UNAT && \
apt-get clean $APT_UNAT
RUN $APT_INSTALL \
bash build-essential bzip2 cmake curl chrpath doxygen \
git python-is-python3 python3 tclsh unzip wget zip
# Dependencies to create Android pkg
RUN $APT_INSTALL \
openjdk-11-jre openjdk-11-jdk openjdk-11-jdk-headless
# Dependecies to run librnp compile time openssl feature detection
RUN $APT_INSTALL qemu-user
ENV ANDROID_SDK_PATH="/opt/android-sdk"
ENV ANDROID_HOME="$ANDROID_SDK_PATH"
ENV ANDROID_SDK_ROOT="$ANDROID_SDK_PATH"
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"
## Copy only the toolchain build script first so Docker layer cache is not
## invalidated by unrelated source changes (C++, CMake, etc). This avoids
## re-downloading the Android SDK and rebuilding all native dependencies
## from scratch on every source edit. The full source tree is copied later
## just before the Gradle build which actually needs it.
ARG SOURCE_PATH=./
COPY $SOURCE_PATH/misc/Android/prepare-toolchain-clang.sh /libretroshare/misc/Android/prepare-toolchain-clang.sh
WORKDIR /libretroshare-build/
RUN /libretroshare/misc/Android/prepare-toolchain-clang.sh install_android_sdk
WORKDIR /libretroshare/
ARG ANDROID_MIN_API_LEVEL=21
ARG LIBRETROSHARE_SOURCE_VERSION="Dockerfile_unset"
ARG GRADLE_BUILD_TASK="build"
ARG JNI_NATIVE_LIBS_ARCHS="arm64-v8a"
ARG NATIVE_TOOLCHAINS_DIR="/libretroshare-native-toolchains/"
## Full source tree needed at this point for the Gradle build. Changes to
## source files will invalidate Docker layer cache from here onward, but all
## toolchain layers above remain cached as long as prepare-toolchain-clang.sh
## is unchanged.
COPY $SOURCE_PATH /libretroshare
RUN ./gradlew $GRADLE_BUILD_TASK \
-Dorg.gradle.project.buildDir=/libretroshare-build/ \
-PANDROID_MIN_API_LEVEL=$ANDROID_MIN_API_LEVEL \
-PNATIVE_TOOLCHAINS_DIR="$NATIVE_TOOLCHAINS_DIR" \
-PJNI_NATIVE_LIBS_ARCHS="$JNI_NATIVE_LIBS_ARCHS" \
-PLIBRETROSHARE_SOURCE_VERSION="$LIBRETROSHARE_SOURCE_VERSION"
WORKDIR /
## Save generated AAR to make life easier to newcomers that might want to use
## this just to build the libretroshare AAR
RUN mv /libretroshare-build/outputs/aar/ /libretroshare-aar/
## Cleanup all the rest now unneded stuff so squashing is more effective
RUN rm -rf /libretroshare-build/
## Clean reamining cruft inside native_toolchains
RUN rm -rf $NATIVE_TOOLCHAINS_DIR/*-build
## Clean apt cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
## No need to keep sources inside the image
RUN rm -rf /libretroshare/