MergeSmali for Users


The basic idea behind patching is to take an existing apk file application, convert it to Smali code, patch the Smali code using Mergesmali, then finally convert the Smali code back to an apk application. apktool is the program for converting to and from Smali code. mergesmali.exe is the program for patching the smali.

When an apk file is converted to Smali, a deep class tree is created. The Smali code for the class com.example.Heatsink would be in the file smali\com\example\Heatsink.smali. The patch for this class would also be called Heatsink.smali, but it need not be in any particular directory.

Here is an example of how to patch an application:

apktool d myapp.apk -o \Scratchdir mergesmali /v \Scratchdir \Extracted\Heatsink.smali apktool b \Scratchdir -o mynewapp.apk jarsigner mynewapp.apk arguments_for_however_you_want_to_sign_this

Note that this is a change from earlier versions. The first argument to mergesmali is the root of the disassembled tree. In the case of multidex it will search smali, smali_classes2, etc. The only time you need to bother with the specific dex is if you are inserting a completely new class.