I’m working on a Dockerfile where I’m trying to create a container environment to run Java code that requires both ADB and AAPT executables. While I’ve been able to successfully execute ADB commands, I’m encountering issues when attempting to run AAPT commands inside the Docker container.
Here’s a simplified version of my Dockerfile:
FROM maven:3.8.6-eclipse-temurin-19-alpine as build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package
FROM eclipse-temurin:19-jdk-alpine
VOLUME /tmp
RUN apk update &&
apk add -v --no-cache android-tools
COPY --from=build /home/app/target/*.jar /project.jar
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /project.jar"]
I’ve included the android-tools package in the container via the apk command, which allows me to run ADB commands successfully. However, I’m unable to execute AAPT commands, which are also required by my Java code.
Am I looking at the wrong package for AAPT, if so What is the correct package to run apk on to get the AAPT executable in the container?
If anyone has experience with using AAPT within a Docker container or any insights into what might be causing this issue, I’d greatly appreciate your help. Thank you!
3
Answers
Since AAPT2 (Android Asset Packaging Tool) is part of the Android SDK Build-Tools, which is a component of the Android SDK… adding that to your Dockerfile should help.
I will be using android-sdk-cmdline-tools-offline.
I added the environment variables (
ANDROID_SDK_ROOT
,BUILD_TOOLS_VERSION
andCMDLINE_TOOLS_VERSION
) to make it easier to reference the Android SDK root path and the build tools version. And I installedwget
andunzip
to download and extract the Android SDK command-line tools.That way, I can download and extract the Android SDK command-line tools to the specified
ANDROID_SDK_ROOT
, adding Android SDK cmdline-tools bin directory to the PATH.I used the
sdkmanager
to install the Android Build-Tools of the specified version (adjustBUILD_TOOLS_VERSION
andCMDLINE_TOOLS_VERSION
as necessary).In the runtime stage, I copied the entire Android SDK installation from the build stage to ensure that
aapt
and other build tools are available in the runtime environment. And I added the build-tools directory to the PATH to make theaapt
executable available in the PATH in your runtime container.to get the AAPT executable in the container is
. The
package only includes the ADB executable.
To fix your Dockerfile, you can change the apk add command to the following:
Here is the updated Dockerfile:
To include AAPT in your Docker container, you’ll need to install the Android SDK or standalone Android build tools package, as AAPT is usually bundled with these.
Here’s an updated Dockerfile that installs the Android build tools, which include AAPT, in your container: