[APP] Zipalign binary and script - Optimize installed applications

Search This thread

senab

Senior Member
Apr 29, 2008
383
31
London, UK
www.senab.co.uk
can someone make a script for windows or a bat file that can zipalign a batch of apks? I am not that ofay with line commands and when i create a new theme (which i often do), i then have to go and zipalign every single apk i have altered 1 at a time..... i do:

Code:
zipalign -f -v 4 E:\app\theapp.apk E:\app\theapp.apk.out

For Windows I sometimes use:

Code:
for /R "C:\path\to\apks" %F IN (*.apk) do (zipalign -f -v 4 %F "%~dpnF.aligned.apk")

Not tested but should work.
 
S

SpiersA

Guest
Is there a major difference in doing this via the phone or the procedure listed here.

Seems like it takes way longer to do it but it dropped the total size of all the supposed zipaligned system apps by over 1MB. I guess what I am asking is if there is a difference in performance?
 

senab

Senior Member
Apr 29, 2008
383
31
London, UK
www.senab.co.uk
Is there a major difference in doing this via the phone or the procedure listed here.

Seems like it takes way longer to do it but it dropped the total size of all the supposed zipaligned system apps by over 1MB. I guess what I am asking is if there is a difference in performance?

There shouldn't be (I haven't tested it though) as all his app does is pad the zip (in the comment field iirc). The script you link to also optipng's all the PNGs in the APKs which explains the size difference.
 

wesgarner

Senior Member
May 10, 2007
825
63
Birmingham, AL
Hey everyone,



I had been messing about with a script to pull apks off my phone, zipalign them and then push them back, but then I saw wesgarner's CM build with a binary and script for use on your phone. I don't really want to mess round with flashing a ROM just for that though, so I've ripped them out and uploaded them below. Another reason is I want to run this manually (with GScript) rather than on boot (as it does in wesgarner's ROM).

I take no credit for this, the binary and script were both taken from wesgarner's CM buiild.

To "install" this, just adb push the two files in the zip below onto your phone with:

Code:
adb shell mount -o remount,rw /system
adb push zipalign /system/bin
adb push zipalign_apks /system/sd/zipalign_apks.sh
adb shell chmod 755 /system/bin/zipalign /system/sd/zipalign_apks.sh
adb shell mount -o remount,ro /system

Then anytime you want to run the script just do:
Code:
adb shell sh /system/sd/zipalign_apks.sh
Or in terminal:
Code:
su
sh /system/sd/zipalign_apks.sh

Has been tested on CM 4.2.7.1 ;)

I think everybody has mostly been having more speed on my ROM because of other things more so than this - but this does give a nice boost
 

Vlad83

Senior Member
Aug 22, 2009
1,465
366
Miami
Just ran the script. After everything is aligned, is it permanent or is this necessary after each boot? Also, what about if a newly aligned app is updated?
 

olearyp

Senior Member
Sep 1, 2009
1,161
151
Just ran the script. After everything is aligned, is it permanent or is this necessary after each boot? Also, what about if a newly aligned app is updated?

Zipalign modifies the structure of the .zip file (renamed to .apk, much like .jar). This will stick between reboots. If a newly aligned app is updated, and the dev is using the standard build process with a recent (1.6 or better) SDK, the new .apk will be aligned by default, but the only way to find out is to attempt to realign it. There's no penalty for doing this.
 

Vlad83

Senior Member
Aug 22, 2009
1,465
366
Miami
Zipalign modifies the structure of the .zip file (renamed to .apk, much like .jar). This will stick between reboots. If a newly aligned app is updated, and the dev is using the standard build process with a recent (1.6 or better) SDK, the new .apk will be aligned by default, but the only way to find out is to attempt to realign it. There's no penalty for doing this.

Yeah, I had a bunch of apps that were not aligned. Also had a temporary scare, half my apps and shortcuts disappeared and I didn't bart before this. I rebooted and the apps reappeared but the shortcuts are still missing...
 

olearyp

Senior Member
Sep 1, 2009
1,161
151
Yeah, I had a bunch of apps that were not aligned. Also had a temporary scare, half my apps and shortcuts disappeared and I didn't bart before this. I rebooted and the apps reappeared but the shortcuts are still missing...

The shortcuts include references into the APK to extract the app icon. When those apps are zipaligned, there's a chance those icons will move within the .zip file. Android (apparently) recognizes this and bails out by removing the shortcut from Home. You can just replace the shortcut, which will refer to the new offset into the APK, and everyone will be happy.

The fact that those icon offsets will now be aligned on a 4-byte boundary accounts for the massive improvement in Home performance if you have many app icons on your Home screen. It's much faster to access resources on 4-byte boundaries with the ARM processor (and many others). For the small penalty of a few disappearing icons I think it's worth it.
 

Grudger

Member
Oct 26, 2012
34
4
Karachi
HTC Rhyme

Confirmed working on HTC Rhyme (Bliss s510b), perfomace boosted - Mind blown :D

It origionally came with Android version 2.3.5, i upgraded to 4.0.3, it was very inefficient, tried several scripts, including Darkdog's Supercharger and few other superchargers.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Hey everyone,

    Zip Align reduces the amount of RAM used during processing running for a major speed increase in running the apps: http://developer.android.com/guide/developing/tools/zipalign.html

    I had been messing about with a script to pull apks off my phone, zipalign them and then push them back, but then I saw wesgarner's CM build with a binary and script for use on your phone. I don't really want to mess round with flashing a ROM just for that though, so I've ripped them out and uploaded them below. Another reason is I want to run this manually (with GScript) rather than on boot (as it does in wesgarner's ROM).

    I take no credit for this, the binary and script were both taken from wesgarner's CM buiild.

    To "install" this, just adb push the two files in the zip below onto your phone with:

    Code:
    adb shell mount -o remount,rw /system
    adb push zipalign /system/bin
    adb push zipalign_apks /system/sd/zipalign_apks.sh
    adb shell chmod 755 /system/bin/zipalign /system/sd/zipalign_apks.sh
    adb shell mount -o remount,ro /system

    Then anytime you want to run the script just do:
    Code:
    adb shell sh /system/sd/zipalign_apks.sh
    Or in terminal:
    Code:
    su
    sh /system/sd/zipalign_apks.sh

    Has been tested on CM 4.2.7.1 ;)