| 1 |
# Dockerfile for cross-compiling for Android and its different architectures. |
| 2 |
# |
| 3 |
# Build the Docker image: |
| 4 |
# docker build -t android-build-env -f /path/to/your/sdk/dockerfile/android-cross-build.dockerfile . |
| 5 |
# -t : Tags the built container with a name |
| 6 |
# -f : Specify dockerfile to be build, replace /path/to/your/sdk with your local path to it |
| 7 |
# |
| 8 |
# Run the Docker container and build the project for a specific architecture: |
| 9 |
# docker run -v /path/to/your/sdk:/mega/sdk -v /path/to/your/vcpkg:/mega/vcpkg [-e ARCH=[arm, arm64, x86, x64]] -it android-build-env |
| 10 |
# -v : Mounts a local directory into the container, replace /path/to/your/sdk and /path/to/your/vcpkg with your local paths |
| 11 |
# -e : Sets an environment variable, `ARCH` environment variable is used to specify the target architecture |
| 12 |
# -it : Starts an interactive terminal session inside the container after the cmake project is configured and build |
| 13 |
|
| 14 |
# Base image |
| 15 |
FROM ubuntu:24.04 |
| 16 |
|
| 17 |
# Install dependencies |
| 18 |
RUN apt-get --quiet=2 update && DEBCONF_NOWARNINGS=yes apt-get --quiet=2 install \ |
| 19 |
autoconf \ |
| 20 |
autoconf-archive \ |
| 21 |
build-essential \ |
| 22 |
cmake \ |
| 23 |
curl \ |
| 24 |
git \ |
| 25 |
libtool-bin \ |
| 26 |
nasm \ |
| 27 |
openjdk-21-jdk \ |
| 28 |
pkg-config \ |
| 29 |
python3 \ |
| 30 |
python3-pip \ |
| 31 |
swig \ |
| 32 |
unzip \ |
| 33 |
wget \ |
| 34 |
zip \ |
| 35 |
1> /dev/null |
| 36 |
|
| 37 |
# Install AWS CLI v2 |
| 38 |
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ |
| 39 |
unzip awscliv2.zip && \ |
| 40 |
./aws/install && \ |
| 41 |
rm -rf awscliv2.zip aws |
| 42 |
|
| 43 |
# Download, extract and set the Android NDK |
| 44 |
RUN mkdir -p /mega/android-ndk && \ |
| 45 |
chmod 777 /mega && \ |
| 46 |
cd /mega/android-ndk && \ |
| 47 |
wget https://dl.google.com/android/repository/android-ndk-r27b-linux.zip && \ |
| 48 |
unzip android-ndk-r27b-linux.zip && \ |
| 49 |
rm android-ndk-r27b-linux.zip |
| 50 |
ENV ANDROID_NDK_HOME=/mega/android-ndk/android-ndk-r27b |
| 51 |
ENV JAVA_HOME=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64 |
| 52 |
ENV PATH=$ANDROID_NDK_HOME:$JAVA_HOME:$PATH |
| 53 |
|
| 54 |
# Set up work directory |
| 55 |
WORKDIR /mega |
| 56 |
|
| 57 |
# Set default architecture |
| 58 |
ENV ARCH=x64 |
| 59 |
|
| 60 |
# Configure and build CMake command, this will be executed when running the container |
| 61 |
CMD ["sh", "-c", "\ |
| 62 |
userdel -f ubuntu && \ |
| 63 |
owner_uid=$(stat -c '%u' /mega/sdk) && \ |
| 64 |
owner_gid=$(stat -c '%g' /mega/sdk) && \ |
| 65 |
groupadd -g $owner_gid me && \ |
| 66 |
echo 'Adding \"me\" user...' && \ |
| 67 |
useradd -r -M -u $owner_uid -g $owner_gid -d /mega -s /bin/bash me && \ |
| 68 |
case ${ARCH} in \ |
| 69 |
arm) \ |
| 70 |
export ANDROID_ARCH='armeabi-v7a';; \ |
| 71 |
arm64) \ |
| 72 |
export ANDROID_ARCH='arm64-v8a';; \ |
| 73 |
x86) \ |
| 74 |
export ANDROID_ARCH='x86';; \ |
| 75 |
x64) \ |
| 76 |
export ANDROID_ARCH='x86_64';; \ |
| 77 |
*) \ |
| 78 |
echo 'error: Unsupported architecture: ${ARCH}' && exit 1;; \ |
| 79 |
esac && \ |
| 80 |
su - me -w 'ANDROID_NDK_HOME,PATH,JAVA_HOME,ANDROID_ARCH,VCPKG_BINARY_SOURCES,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_ENDPOINT_URL' -c ' \ |
| 81 |
cmake --preset mega-android -B buildAndroid -S sdk \ |
| 82 |
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ |
| 83 |
-DANDROID_ABI=${ANDROID_ARCH} && \ |
| 84 |
cmake --build buildAndroid' && \ |
| 85 |
exec /bin/bash"] |