Skip to content

Instantly share code, notes, and snippets.

@babs
Forked from sebfisch/replace-classes-in-apk.sh
Last active August 29, 2015 14:18
Show Gist options
  • Save babs/4aa16473cb048f372091 to your computer and use it in GitHub Desktop.
Save babs/4aa16473cb048f372091 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Replaces classes in Android Package Files
# (c) Sebastian Fischer, CC-BY
# Can be used to rebuild an App with a modified version of a used library,
# as required for closed works that link to an LGPL library.
# Depends on: https://code.google.com/p/dex2jar/
APK=path/to/SomeApp.apk
JAR=path/to/interface-compatible-classes.jar
PKG=replaced/package/path # example: PKG=org/mapsforge
unzip $APK classes.dex # extract original classes
d2j-dex2jar.sh -f -o classes.jar classes.dex # and convert them to .jar
rm classes.dex
unzip $JAR $PKG/* # extract alternative classes
jar uvf classes.jar $PKG # and replace originals
rm -rf $PKG
d2j-jar2dex.sh -f -o classes.dex classes.jar # convert back to .dex
rm classes.jar
jar uvf $APK classes.dex # replace .dex in .apk
rm classes.dex
mv $APK unsigned.apk
d2j-apk-sign.sh -f -o $APK unsigned.apk # sign modified .apk
rm unsigned.apk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment