first commit

This commit is contained in:
root
2026-03-30 10:05:53 +00:00
commit 59f6583862
8465 changed files with 541514 additions and 0 deletions

93
docker/Containerfile Normal file
View File

@@ -0,0 +1,93 @@
FROM ubuntu:24.04
###############################################################################
### Tools Configuration ###
# Java JDK Setup
ARG JDK_VERSION="17"
# Gradle Setup
ARG GRADLE_VERSION="8.4"
ARG GRADLE_INSTALL_PATH="/opt/gradle"
# CMake Setup (https://github.com/Kitware/CMake)
ARG CMAKE_VERSION="3.31.5"
ARG CMAKE_PKG="cmake-${CMAKE_VERSION}-linux-x86_64.sh"
ARG CMAKE_REPO_URL="https://github.com/Kitware/CMake/releases/download"
ARG CMAKE_PKG_URL="${CMAKE_REPO_URL}/v${CMAKE_VERSION}/${CMAKE_PKG}"
# Android Setup
ARG ANDROID_SDK_VERSION="31"
ARG ANDROID_NDK_VERSION="26.0.10792818"
ARG ANDROID_BUILD_TOOLS_VERSION="30.0.2"
ARG ANDROID_INSTALL_PATH="/opt/android-studio"
###############################################################################
# Set Environment Variable for no user interaction with APT
ARG DEBIAN_FRONTEND=noninteractive
###############################################################################
# Install system packages
RUN apt-get update && \
apt-get install --yes --no-install-recommends apt-utils && \
apt-get install --yes --no-install-recommends \
openjdk-${JDK_VERSION}-jdk \
wget \
unzip \
curl \
git \
zip \
ninja-build \
build-essential \
ca-certificates && \
apt-get clean --yes && \
rm -rf /var/lib/apt/lists/*
# CMake Installation
RUN wget ${CMAKE_PKG_URL} -O /tmp/cmake.sh && \
chmod +x /tmp/cmake.sh && \
/tmp/cmake.sh --skip-license --prefix=/usr/local && \
rm -f /tmp/cmake.sh
# Gradle Installation
RUN wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -O /tmp/gradle.zip && \
unzip /tmp/gradle.zip -d /opt && \
ln -s /opt/gradle-${GRADLE_VERSION} ${GRADLE_INSTALL_PATH} && \
ln -s ${GRADLE_INSTALL_PATH}/bin/gradle /usr/bin/gradle && \
rm /tmp/gradle.zip
ENV PATH="${GRADLE_INSTALL_PATH}/bin:${PATH}"
# Install Android SDK Command Line Tools
RUN mkdir -p ${ANDROID_INSTALL_PATH}/cmdline-tools && \
wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/tools.zip && \
unzip /tmp/tools.zip -d ${ANDROID_INSTALL_PATH}/cmdline-tools && \
mv ${ANDROID_INSTALL_PATH}/cmdline-tools/cmdline-tools ${ANDROID_INSTALL_PATH}/cmdline-tools/latest && \
rm /tmp/tools.zip
ENV ANDROID_SDK_ROOT=${ANDROID_INSTALL_PATH}
ENV PATH="${ANDROID_INSTALL_PATH}/cmdline-tools/latest/bin:${PATH}"
# Accept Android SDK-Manager License
RUN yes | sdkmanager --licenses
# Install Android Tools, SDK and NDK
RUN sdkmanager --update && \
sdkmanager \
"platform-tools" \
"platforms;android-${ANDROID_SDK_VERSION}" \
"build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
"ndk;${ANDROID_NDK_VERSION}"
ENV ANDROID_NDK_HOME=${ANDROID_INSTALL_PATH}/ndk/${ANDROID_NDK_VERSION}
ENV PATH=${ANDROID_INSTALL_PATH}/cmdline-tools/latest/bin:${ANDROID_INSTALL_PATH}/platform-tools:${ANDROID_INSTALL_PATH}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}:$PATH
# Container working directory
WORKDIR /workspace
# Add and Setup Container Entry Point Script
COPY ./scripts/entrypoint.sh /opt/entrypoint.sh
RUN chmod +x /opt/entrypoint.sh
ENTRYPOINT ["/opt/entrypoint.sh"]
###############################################################################

46
docker/Makefile Normal file
View File

@@ -0,0 +1,46 @@
###############################################################################
SHELL = /bin/bash
SCRIPTS="./scripts"
.PHONY: all help setup build
###############################################################################
### Main Targets ###
# make help
help:
@ echo ""
@ echo "Usage:"
@ echo " make setup - Install container environment"
@ echo " make build - Build project through the container"
@ echo " make build_release - Build project release through the container"
@ echo " make create_container - Local build the container"
@ echo ""
# make setup (Install container/docker image)
setup: scripts_exec_permission
@ $(SCRIPTS)/install_container_image.sh
# make build
build: scripts_exec_permission
@ $(SCRIPTS)/build_android_project.sh
# make build_release
build_release: scripts_exec_permission
@ $(SCRIPTS)/build_android_project.sh --release
# make create_container
create_container: scripts_exec_permission
@ $(SCRIPTS)/build_container_image.sh
###############################################################################
### Auxiliary Targets ###
scripts_exec_permission:
@ chmod +x $(SCRIPTS)/*.sh
###############################################################################

60
docker/README.md Normal file
View File

@@ -0,0 +1,60 @@
# Container Support
An [OCI](https://opencontainers.org/) container image to generate an isolate environment that includes all the needed tools for building the project is available.
This container can be used from any OCI compatible container tool, such as Docker, Podman, etc.
The main purpose of this is to provide:
- An easy way to build the project from CLI (Command Line Interface), without the need of installing and using a full android-studio.
- A virtual container environment to use it for automatically building the project during CI (Continuous Integration) via Github actions.
## Usage
The next files are provided to ease the usage of the container:
- **Makefile:** An UNIX Makefile to abstract and simplify the usage of the container technology.
- **Containerfile:** The container definition file that can be used to build and create the container image.
The **Makefile** offers the next commands:
```bash
make setup - Download and install the container image environment needed for project build.
make build - Run the container to build the project for debug/release and multiple architectures.
make build_release - Run the container to build the project for release and common architecture (ARMv8).
make create_container - Build the container image from the Containerfile (no needed if you have install it via make setup).
```
The **Containerfile** has been used to create the corresponding container image and then this has been published to [Docker Hub](https://hub.docker.com/repository/docker/jriosbyte/android-builder-soh) registry, so you just need to install the container from the remote registry via `make setup`.
## Project Build
First time that you get the repository, you need to download and install the container:
```bash
make setup
```
Then, you can build the project via:
```bash
make build
```
The resulting image will be located at Android/app/build/outputs/apk/release/app-release.apk
## Publishing a new container image
In case some modifications needs to be done in the image and a new image version need to be created, follows the next steps:
1. Do the modifications in the Containerfile.
2. Increase the *IMAGE_TAG* version at *scripts/set_container_vars.sh*.
3. Create the new image version via `make create_container`.
4. Publish the image to the registry via `scripts/publish_container_image.sh`.
**Note:** you need to have access to the registry repository as owner or collaborator.

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
###############################################################################
# Actual script directory path
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Load Container IMAGE_NAME and IMAGE_TAG variables
source ${DIR}/set_container_vars.sh
# Setup
IMAGE_NAME="${REGISTRY_REPO}:${IMAGE_TAG}"
CONTAINER_NAME="android_builder_soh"
PROJECT_PATH=$(realpath "${DIR}/../../")
###############################################################################
# Check if only release build flag was provided
ONLY_RELEASE_BUILD="false"
if [[ "$1" == "--release" ]] || [[ "$1" == "-r" ]]; then
ONLY_RELEASE_BUILD="true"
fi
# Set type of build
GRADLEW_BUILD_TYPE="build"
if [[ "$ONLY_RELEASE_BUILD" == "true" ]]; then
GRADLEW_BUILD_TYPE="assembleRelease"
fi
# Header
echo ""
echo "-----------------------------------------------------------"
echo "-- Android Project Build --"
echo "-----------------------------------------------------------"
echo "Building project '${PROJECT_PATH}'..."
echo ""
# Check if the project path exists
if [ ! -d "$PROJECT_PATH" ]; then
echo "Error: Project path not found"
echo ""
exit 1
fi
# Run Container to build
docker run --network="host" --rm \
--name $CONTAINER_NAME \
-v "$PROJECT_PATH":/workspace \
-w /workspace \
$IMAGE_NAME \
bash -c "cp -a local.properties Android/ && cd Android && ./gradlew ${GRADLEW_BUILD_TYPE}"
BUILD_RESULT=$?
# Verify the result
echo ""
if [ $BUILD_RESULT -ne 0 ]; then
echo "Build Fail (error code ${BUILD_RESULT})"
exit $BUILD_RESULT
else
echo "Build success"
fi
exit 0
###############################################################################

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
###############################################################################
# Actual script directory path
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Load Container IMAGE_NAME and IMAGE_TAG variables
source ${DIR}/set_container_vars.sh
# Setup
IMAGE_NAME="${IMAGE_NAME}:${IMAGE_TAG}"
DOCKER_FILE="Containerfile"
###############################################################################
# Build the image
echo ""
echo "-----------------------------------------------------------"
echo "-- Container Image Build --"
echo "-----------------------------------------------------------"
echo "Building '${IMAGE_NAME}'..."
docker build --network="host" -t ${IMAGE_NAME} --file $DOCKER_FILE .
build_result=$?
if [[ $build_result -ne 0 ]]; then
echo ""
echo "ERROR: Image build fail."
exit 1
fi
echo ""
echo "Image '${IMAGE_NAME}' build success."
echo ""
echo "Clean-up build cache..."
docker builder prune -f
echo "Done"
echo ""
exit 0
###############################################################################

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
###############################################################################
# Enable exit on any error
set -e
###############################################################################
# Setup Android SDK and NDK paths in project local.properties
echo "sdk.dir=${ANDROID_SDK_ROOT}" > /workspace/local.properties
echo "ndk.dir=${ANDROID_NDK_HOME}" >> /workspace/local.properties
# Execute any received command
exec "$@"
exit 0
###############################################################################

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
###############################################################################
# Actual script directory path
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Load Container IMAGE_NAME and IMAGE_TAG variables
source ${DIR}/set_container_vars.sh
###############################################################################
# Container Pull Installation
echo ""
echo "-----------------------------------------------------------"
echo "-- Installing Container Image --"
echo "-----------------------------------------------------------"
echo "Pulling '${REGISTRY_REPO}:${IMAGE_TAG}'..."
docker pull "${REGISTRY_REPO}:${IMAGE_TAG}"
if [[ $? -ne 0 ]]; then
echo "Error: Image pull fail."
exit 1
fi
echo "Image '${REGISTRY_REPO}:${IMAGE_TAG}' installation success"
echo ""
exit 0
###############################################################################

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
###############################################################################
# Actual script directory path
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Load Container IMAGE_NAME and IMAGE_TAG variables
source ${DIR}/set_container_vars.sh
###############################################################################
# Header
echo ""
echo "-----------------------------------------------------------"
echo "-- Publishing Container Image --"
echo "-----------------------------------------------------------"
# Check if the image is available
if ! docker image inspect "${IMAGE_NAME}:${IMAGE_TAG}" >/dev/null 2>&1; then
echo "Error: ${IMAGE_NAME}:${IMAGE_TAG} not found."
echo "Note: The image need to be build first."
exit 1
fi
# Login to the remote registry
docker login
if [[ $? -ne 0 ]]; then
echo "Error: Login to registry fail."
exit 1
fi
# Tag Image for remote registry
docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "${REGISTRY_REPO}:${IMAGE_TAG}"
# Publish the image
echo "Publishing container image ${REGISTRY_REPO}:${IMAGE_TAG} to registry..."
docker push "${REGISTRY_REPO}:${IMAGE_TAG}"
if [[ $? -ne 0 ]]; then
echo "Error: Image publish fail."
exit 1
fi
echo ""
echo "Image published successfully."
exit 0
###############################################################################

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
###############################################################################
IMAGE_NAME="android-builder-soh"
IMAGE_TAG="v1.0.0"
REGISTRY_REPO="jriosbyte/${IMAGE_NAME}"
export IMAGE_NAME IMAGE_TAG REGISTRY_REPO
###############################################################################