Remove All Ads from XDA

# [APP] Zipalign binary and script - Optimize installed applications

383 posts
Thanks Meter: 32

By senab, Senior Member on 4th December 2009, 07:07 PM
5th December 2009, 01:37 PM |#21
OP Senior Member
London, UK
Thanks Meter: 32

Donate to Me
More
Quote:
Originally Posted by turboyo

This isnt working for me bc of the .sh after zipalign_apks .. do i rename the zipalign_apks to zipalign_apks.sh after unzipping?

edit:that worked THANKS!

My bad, i've updated the first post with a fixed adb push command. I thought I had renamed it to .sh in the zip but I obviously hadn't.

5th December 2009, 01:43 PM |#22
OP Senior Member
London, UK
Thanks Meter: 32

Donate to Me
More
Quote:
Originally Posted by MontAlbert

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.
5th December 2009, 02:07 PM |#23
Senior Member
Baltimore
Thanks Meter: 5

More
Lucid Script
Quote:
Originally Posted by garz

yeah so su? then #lucid -z? cause that did nothing for me...

this would require you have my script first .. if you have it make sure you do the "-u" option to get to script v1.60.37
SpiersA
5th December 2009, 05:02 PM |#24
Guest
Thanks Meter: 0

More
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?
5th December 2009, 05:21 PM |#25
OP Senior Member
London, UK
Thanks Meter: 32

Donate to Me
More
Quote:
Originally Posted by SpiersA

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.
5th December 2009, 07:54 PM |#26
Senior Member
Birmingham, AL
Thanks Meter: 62

More
Quote:
Originally Posted by senab

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
6th December 2009, 12:16 AM |#27
Senior Member
Miami
Thanks Meter: 331

More
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?
6th December 2009, 01:41 AM |#28
Senior Member
Thanks Meter: 151

More
Quote:
Originally Posted by Vlad83

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.
6th December 2009, 01:57 AM |#29
Senior Member
Miami
Thanks Meter: 331

More
Quote:
Originally Posted by olearyp

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...
6th December 2009, 05:33 AM |#30
Senior Member
Thanks Meter: 151

More
Quote:
Originally Posted by Vlad83

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.
7th December 2009, 09:03 PM |#31
Member
Thanks Meter: 1

More
works great!

 Tags 1.21 gigawatts!

 Guest Quick Reply (no urls or BBcode) Message:
 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode