From 45d0a00088b79931ffb0f8eb9ca0df6e278a4b87 Mon Sep 17 00:00:00 2001 From: Ben Curtis Date: Mon, 2 Oct 2023 06:47:40 -0400 Subject: [PATCH] Add Docker support (#3351) * add Docker image * use latest version in Docker image * Dockerfile optimizations from PR feedback --- .dockerignore | 1 + DOCKER.md | 25 +++++++++++++++++++++++++ Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 4 files changed, 69 insertions(+) create mode 100644 .dockerignore create mode 100644 DOCKER.md create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f59ec20a --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 00000000..372c3af9 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,25 @@ +# Apktool in Docker +We provide an easy way to leverage `apktool`, along with common Android tools such as `zipalign` and `apksigner`, all from within Docker. + +## Building the Docker image +To build the image, use the included Dockerfile: +```bash +docker build -t apktool:latest . +``` + +## Using the Docker image +The best way to use the image is to create aliases to run the internal commands: +```bash +alias apktool="docker run --rm -ti --name=apktool -v \"${PWD}:${PWD}\" -w \"${PWD}\" apktool:latest apktool" +alias zipalign="docker run --rm -ti --name=zipalign -v \"${PWD}:${PWD}\" -w \"${PWD}\" apktool:latest zipalign" +alias apksigner="docker run --rm -ti --name=apksigner -v \"${PWD}:${PWD}\" -w \"${PWD}\" apktool:latest apksigner" +``` + +## Running the commands +You can then utilize these commands as you would if they were natively installed: +```bash +apktool d My.apk -o MyFolder +apktool b MyFolder -o MyNew.apk +zipalign -p -f 4 MyNew.apk MyNewAligned.apk +apksigner sign --ks My.keystore MyNewAligned.apk +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..37a5ef11 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM openjdk:21-slim + +# Latest version as of 2023.10.01 +# Ref: https://developer.android.com/studio/index.html#command-line-tools-only +ARG COMMAND_LINE_TOOLS_VERSION=10406996 + +ARG ANDROID_SDK_ROOT=/opt/android-sdk + +RUN \ + # Update + apt-get update &&\ + \ + # Apktool + apt-get install --no-install-recommends -y curl zipalign &&\ + curl -o /usr/local/bin/apktool https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool &&\ + curl -L -o /usr/local/bin/apktool.jar $(curl -s https://api.github.com/repos/iBotPeaches/Apktool/releases/latest |grep browser_download_url |awk '{print $2}' |sed 's/"//g') &&\ + chmod +x /usr/local/bin/apktool /usr/local/bin/apktool.jar &&\ + \ + # Android SDK + apt-get install -y --no-install-recommends \ + git \ + openssl \ + wget \ + unzip \ + sdkmanager &&\ + curl -o /tmp/tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${COMMAND_LINE_TOOLS_VERSION}_latest.zip &&\ + mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools &&\ + unzip -q /tmp/tools.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools &&\ + mv ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/latest &&\ + rm -v /tmp/tools.zip &&\ + mkdir -p /root/.android/ && touch /root/.android/repositories.cfg &&\ + yes | sdkmanager --licenses &&\ + export BUILD_TOOLS_VERSION=$(sdkmanager --list |grep build-tools |grep -v rc |awk '{print $1}' |sed 's/build-tools;//g' |sort |tail -n1) &&\ + sdkmanager --install "build-tools;${BUILD_TOOLS_VERSION}" &&\ + ln -s ${ANDROID_SDK_ROOT}/build-tools/${BUILD_TOOLS_VERSION} /opt/bin &&\ + \ + # Cleanup + rm -rf /var/lib/apt/lists/* + +ENV PATH ${PATH}:/opt/bin + +CMD ["/usr/local/bin/apktool"] diff --git a/README.md b/README.md index b60a497a..94913b13 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ If you discover a security vulnerability within Apktool, please send an e-mail t - [Downloads Mirror](https://connortumbleson.com/apktool/) - [How to Build](https://ibotpeaches.github.io/Apktool/build/) - [Documentation](https://ibotpeaches.github.io/Apktool/documentation/) +- [Use in Docker](./DOCKER.md) - [Bug Reports](https://github.com/iBotPeaches/Apktool/issues) - [Changelog/Information](https://ibotpeaches.github.io/Apktool/changes/) - [XDA Post](https://forum.xda-developers.com/t/util-dec-2-2020-apktool-tool-for-reverse-engineering-apk-files.1755243/)