Dockerfile67 lines · 2899 chars # Dockerfile for building Karing Kotlin/Flutter Android app from source
FROM ubuntu:jammy-20260217
# Non-interactive apt installs
ENV DEBIAN_FRONTEND=noninteractive
# System dependencies (align with runtime_requirements)
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
curl \
unzip \
git \
ca-certificates \
build-essential \
openjdk-17-jdk \
zip \
lib32stdc++6 \
&& rm -rf /var/lib/apt/lists/*
# Android SDK location
ENV ANDROID_SDK_ROOT=/usr/local/android-sdk
# Install Android command-line tools and platform components
RUN mkdir -p "$ANDROID_SDK_ROOT/cmdline-tools" && \
curl -o /tmp/commandlinetools-linux.zip -L https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip && \
unzip /tmp/commandlinetools-linux.zip -d "$ANDROID_SDK_ROOT/cmdline-tools" && \
rm /tmp/commandlinetools-linux.zip && \
# Detect sdkmanager location and install components
if [ -f "$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools/bin/sdkmanager" ]; then \
SDKMANAGER="$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools/bin/sdkmanager"; \
else \
SDKMANAGER="$ANDROID_SDK_ROOT/cmdline-tools/tools/bin/sdkmanager"; \
fi && \
yes | "$SDKMANAGER" --sdk_root="$ANDROID_SDK_ROOT" "platform-tools" && \
yes | "$SDKMANAGER" --sdk_root="$ANDROID_SDK_ROOT" "platforms;android-34" "build-tools;34.0.0" "ndk;26.3.11579264"
# Install Gradle (system Gradle 8.x compatible with AGP 8+)
RUN curl -o /tmp/gradle-8.14.3-all.zip -L https://services.gradle.org/distributions/gradle-8.14.3-all.zip && \
mkdir -p /opt/gradle-8.14.3 && \
unzip -d /opt/gradle-8.14.3 /tmp/gradle-8.14.3-all.zip && \
rm /tmp/gradle-8.14.3-all.zip
# Flutter SDK (stable) installation
RUN git clone https://github.com/flutter/flutter.git /opt/flutter -b stable
# Environment for Gradle and Flutter
ENV GRADLE_VERSION=8.14.3
ENV GRADLE_ROOT=/opt/gradle-8.14.3/gradle-${GRADLE_VERSION}
ENV PATH="$GRADLE_ROOT/bin:$PATH"
# Update PATH to include Android tools, Flutter
ENV ANDROID_TOOLS_PATH="$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/platform-tools"
ENV PATH="$PATH:$ANDROID_TOOLS_PATH:/opt/flutter/bin"
# Workspace for building the app
WORKDIR /workspace
COPY . .
# Create local.properties for Flutter Gradle plugin to locate Flutter SDK and Android SDK if missing
RUN bash -lc 'if [ ! -f android/local.properties ]; then mkdir -p android; echo "flutter.sdk=/opt/flutter" > android/local.properties; echo "sdk.dir=/usr/local/android-sdk" >> android/local.properties; fi'
# Build the Android app (Gradle-based) from source using system Gradle
RUN bash -lc "cd android && /opt/gradle-8.14.3/bin/gradle clean && /opt/gradle-8.14.3/bin/gradle assembleDebug"
# Default to an interactive shell to inspect the image
CMD ["/bin/bash"]