Add Docker support (#3351)

* add Docker image

* use latest version in Docker image

* Dockerfile optimizations from PR feedback
This commit is contained in:
Ben Curtis 2023-10-02 06:47:40 -04:00 committed by GitHub
parent a1f4a4b6c8
commit 45d0a00088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 0 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
*

25
DOCKER.md Normal file
View File

@ -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
```

42
Dockerfile Normal file
View File

@ -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"]

View File

@ -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/)