Skip to content

Instantly share code, notes, and snippets.

@sebfisch
Created May 22, 2012 08:58
Show Gist options
  • Save sebfisch/2767707 to your computer and use it in GitHub Desktop.
Save sebfisch/2767707 to your computer and use it in GitHub Desktop.
Replaces classes in Android Package Files
#!/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