Skip to content

Instantly share code, notes, and snippets.

@Alia5
Forked from sebfisch/replace-classes-in-apk.sh
Created September 21, 2016 03:03
Show Gist options
  • Save Alia5/524637566b7715a89e6bbd342cb16cd3 to your computer and use it in GitHub Desktop.
Save Alia5/524637566b7715a89e6bbd342cb16cd3 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