Files
apk-mitm/docs/troubleshooting/patching-fails.md
T

4.2 KiB

Patching an APK fails

The following page deals with issues that arise while running apk-mitm. Check out the general Troubleshooting Guide page if you're having problems after that (like not being able to see the HTTPS traffic of a patched app).

To understand "patch-time issues" you first need to understand a bit about how apk-mitm works, specifically what happens when you use it to patch an APK:

  1. The APK is decoded using Apktool
  2. apk-mitm applies its patches to the decoded files
  3. The patched APK is encoded again using Apktool
  4. The patched APK is signed using uber-apk-signer

As you can see, only one of these tasks is really performed by apk-mitm. The other three are fully delegated to other tools, which could also be used on their own, but are automatically executed by apk-mitm for convenience.

Finding the culprit

A good first troubleshooting step is to figure out which tool is causing the patching to fail. This can sometimes be a little tricky, but an easy way to start is to skip the task that applies the patches by running your command again with the --skip-patches flag:

$ apk-mitm --skip-patches <path-to-apk>

If you were getting errors before and this command runs successfully, then you've probably discovered a bug in apk-mitm and should report it here.

If, however, this command still returns an error, then the hunt continues. There's many possible causes at this point, but the most common one is that Apktool has trouble decoding or encoding the APK, so that's what the rest of this guide is going to focus on. If your issue has nothing to do with Apktool, then it's probably a good idea to open an issue.

Dealing with Apktool issues

APKs can be pretty complex and they're not really meant to be taken apart again once they've been packaged up by the developer, so it's no surprise that Apktool sometimes has trouble with certain APKs.

In these cases you should report the issue directly to Apktool, but please keep in mind the following things:

Once you've eliminated these two causes, you should try to reproduce the issue in a setup where apk-mitm isn't involved. You can do this by installing the latest version of Apktool and running:

apktool decode app.apk --output app-decoded
apktool build app-decoded --output app-rebuilt.apk --use-aapt2
# Or, if the above command fails:
apktool build app-decoded --output app-rebuilt.apk

This is basically equivalent to running apk-mitm with the --skip-patches flag, but by running the individual commands yourself you can make sure that it's actually an issue with Apktool, which you can then report through their issue tracker.