The following is an overview of the process I followed in creating the live wallpapers found in the first post. These instructions are intended to serve as a guide to those interested in creating their own modifications.
- Asus MyWater APK (you can grab a copy here)
- android-apktool - tool for reengineering Android apk files (here)
- roptipng - modification to OptiPNG PNG optimizer (here)
- SignApk.jar - (Google search)
- zipalign - archive alignment tool (included in Android SDK)
- Decoding the APK
Using apktool, decode the APK to retrieve the resources into nearly original form. In this example, the decoded files are placed in a directory called MyWaterDir
apktool decode MyWater.apk MyWaterDir
- Modifying the package name
The package name is a unique identifier used by Android to manage the installed applications. The easiest package name modification simply involves changing all instances of asus
to another unique identifier.
Using your favorite editor (I like gVim
), modify the package name found in MyWaterDir/AndroidManifest.xml
) and MyWaterDir/res/xml/glwallpaper.xml
). There are only 2 instances of the package name in the XML files.
The package name is also embedded in the smali disassembly files (MyWaterDir/smali/com/asus/livewallpaper/gl/*.smali
). In all, there are 1791 instances of the package name in the smali files that must be updated. My recommendation is to find an editor that makes it easy to perform a global search and replace.
The package name must also match the folder hierarchy under the smali folder (MyWaterDir/smali/com/asus/livewallpaper/gl/
). Change the name of the asus
folder to match the new unique identifier selected for the application.
- Update the application name and settings text
Using your favorite editor, modify the text found in MyWaterDir/res/values/strings.xml
. Rather than worry about translations for my updated text, I chose to remove all but the default by deleting the MyWaterDir/res/values-XX
folders (keep values-large).
- Update the image resources
The image resources are found in MyWaterDir/res/drawable-mdpi
. You can modify these images or use your own. For the purpose of this tutorial there is a requirement that they maintain the original file naming scheme. It is also important to note that if you provide an image with different dimensions, it will be scaled to match the dimensions of the original image. Modifications to the smali disassembly files are required to overcome this limitation.
As an optional step, you can optimize the PNG image resources to reduce their size.
roptipng -o7 MyWaterDir/res/drawable-mdpi/*.png
- Build the APK
Now that the desired modifications have been made, build the APK using apktool.
apktool build MyWaterDir MyWaterModified_unsigned.apk
- Sign the APK
The Android system requires that all installed applications be digitally signed with a certificate whose private key is held by the application's developer. I followed the instructions found here
for generating my keys and using them to sign the APK. It should also be possible to sign the APK using the approach recommended at developer.android.com
java -jar signapk.jar certificate.pem key.pk8 MyWaterModified_unsigned.apk MyWaterModified_signed.apk
- Zipalign the APK
the APK to optimize the way it is packaged in order to enable the Android operating system to interact with the application more efficiently. The benefit of this step is a reduction in the amount of RAM consumed when running the application.
zipalign -f -v 4 MyWaterModified_signed.apk MyWaterModified.apk
The truly adventurous can take a stab at modifying the smali
disassembly prior to building the APK. The syntax is a bit difficult to follow at first, but with proper modifications you can adjust the image dimensions, rendering locations, and much more. I found it useful to pull the classes.dex
file from the APK, convert it from .dex to .class format using dex2jar
, and then browse the reconstructed source using JD-GUI
. It is important to remember that the reconstructed source is not a 100% match to the original source code. However, it is useful for comparing against and understanding the corresponding smali source.
I hope some of you find this information useful. If so, be sure to say thanks
via the button below.