cd /news/developer-tools/full-tutorial-to-patch-apks-on-andro… · home topics developer-tools article
[ARTICLE · art-9166] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Full tutorial to patch APKs on Android using apk-mitm and APKLab. Support for bundle APKs.

This article provides a tutorial for patching Android APKs using the tools apk-mitm and APKLab, including support for bundle APKs (multiple APK files). It outlines steps to extract, decompile, edit, rebuild, and sign APKs, with specific instructions for handling single APKs versus bundle APKs using Split APKs Installer (SAI). The process concludes with installing the patched app on a device and optionally using a proxy SSL certificate for network inspection.

read1 min views19 publishedJul 19, 2022

Patch APK #

Full tutorial to patch APKs on Android using apk-mitm and APKLab. Support for bundle APKs.

Pull APK

adb shell pm list packages
adb shell pm path <package_name>

If the app contains a single APK:

adb pull /data/app/~~SzA2evEyrPV2ucUpwPzYYQ==/some_path==/base.apk base.apk

If it's a bundle APK (multiple APK files):

  • Install Split APKs Installer (SAI)
  • Backup the app to a .apks file
  • Load the file to your computer
  • Extract the .apks file (it's an archive!)
  • Create a copy of the .apks file, we will need it later when rebuilding the app

Patch APK

Open base.apk with APKLab with options:

  • Only main classes
  • Decompile Java

Inspect the Java code in the java_src directory, find the function you want to edit.

When found, go to its .smali file equivalent in the smali directory, do your edit and save.

Right-click on the apktool.yml file: APKLab: Rebuild the APK.

The APK file is generated at dist/base.apk.

If you are working on a single APK, you can install it to your phone:

adb install dist/base.apk

Build bundle APK

  • Open your copy of the .apks file as an archive
  • Delete the base.apk file from the archive
  • Add your dist/base.apk patch APK file to the archive

Using apk-mitm

apk-mitm my_app-edited.apks

  ╭ apk-mitm v1.2.1
  ├ apktool v2.6.1
  ╰ uber-apk-signer v1.2.1

  Using temporary directory:
  /tmp/apk-mitm-ab640ef99e9eacd6b96f033651301328

  ✔ Extracting APKs
  ✔ Patching base APK
  ✔ Signing APKs
  ✔ Compressing APKs

   Done!  Patched file: ./my_app-edited-patched.apks

Quick SSL/HTTPS MITM patch

Use the --certificate parameter your proxy SSL certificate

apk-mitm --certificate charles_proxy_certificate.pem my_app-edited.apks

Install bundle APK

Enjoy! 💕

── more in #developer-tools 4 stories · sorted by recency
── more on @apklab 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/full-tutorial-to-pat…] indexed:0 read:1min 2022-07-19 ·