philjay-mpandroidchart
SUCCESS
40m 37s
History Source
SummaryIterations2Transcript36Dockerfile
Dockerfile44 lines · 1455 chars
# Multi-stage Dockerfile to build MPAndroidChart (MPChartLib + MPChartExample) from source
FROM circleci/android:api-28 AS builder

# Ensure we run as root for installation tasks
USER root

# Android SDK environment
ENV ANDROID_HOME=/opt/android-sdk
ENV ANDROID_SDK_ROOT=${ANDROID_HOME}
ENV PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools

# Prepare workspace and dependencies
WORKDIR /workspace

# Copy source code into the image
COPY . /workspace

# Ensure Gradle wrapper is executable
RUN chmod +x gradlew

# Provide local properties so Gradle can find the SDK (use the image's default SDK path if present)
RUN mkdir -p "$ANDROID_HOME" && echo "sdk.dir=$ANDROID_HOME" > local.properties

# Build the project from source (builds both MPChartLib and MPChartExample via the Gradle wrapper)
RUN ./gradlew build

# Collect APKs into a single artifacts directory inside the builder
RUN mkdir -p /workspace/apk
RUN sh -lc 'for f in $(find . -name "*.apk" 2>/dev/null); do cp "$f" /workspace/apk/; done' || true

# Stage 2: runtime container with artifacts only
FROM debian:bookworm-slim AS runtime

# Create directory for APKs
RUN mkdir -p /app/apk

# Copy built APKs from the builder stage (robust against folder structure)
COPY --from=builder /workspace/apk/ /app/apk/

WORKDIR /app

# Default command: list APKs if present
CMD ["bash","-lc","ls -la /app/apk || true && echo APK artifacts available in /app/apk"]