My zipalign restore script

Last Updated:

  1. Hawker

    Hawker Well-Known Member

    What is "zipaligning"
    The Android SDK includes a tool called zipalign that optimizes the way an application is packaged. Running this zipalign function against your applications enables Android to interact with them more efficiently at run time and thus has the potential to make it, and the overall system run faster. Most custom ROM's come with their apps zipaligned as standard, so you need not worry about anything bundled into the ROM itself.
    The difficulty lies in how to zipalign any new .apk files that you subsequently install.

    How is this acheived?
    Most commonly, zipaligning newly installed applications is done on a boot of the hansdet via a startup script in /system/etc/init.d. It will usually have a file name that logically has "zipalign" included in it. For example, in CheckROM V6, this file is called S96zipalign. Now each ROM may be different, but typically, this script will look through every .apk file found in /system/app and /data/app folders, and will zipalign each application it finds if it has not been done already. The actual zipalign process is performed by the Android SDK program, /system/xbin/zipalign.

    How does ZipAlignRestore fit in?
    I have just discovered what may be considered a fairly significant flaw in CRR6, and all its previous versions, and indeed in every other custom ROM that I've looked into (by examining the ROM's installation .zip files). The Android SDK zipalign program itself is NOT bundled in with the ROM. So in essence, the init.d script will try to zipalign your applications, but nothing will actually be done as the important program that performs this task is missing :eek:

    I have therefore developed a CWM flashable zip to do this. It restores the missing zipalign program into /system/xbin so that the init.d script will actually succeed in zipaligning any non pre-loaded ROM .apk's (ie. the ones you install after the initial flash). It does not restore an init.d script to perform the zipaligning on bootup, as not all ROMs will have this feature in the startup scripts. As each ROM could be different, I have omitted this intentionally.

    After flashing ZipAlignRestore, all your own, non-ROM apps will then become zipaligned on the next boot, providing of course you have a zipalign script in init.d

    If you do not have a file similar to zipalign in /system/etc/init.d then your ROM is not attempting to retrospectively zipalign, so there is no point flashing ZipAlignRestore as it will have absolutely no effect on you. If you already have a file called /system/xbin/zipalign, then again, there is no point flashing ZipAlignRestore, as you already have the necessary tools to perform this task.

    ZipAlignRestore can be downloaded in post#2 below

    NeatLite 1.2 correctly zip-aligns, so you will not need to concern yourself over this if on this ROM.

  2. Hawker

    Hawker Well-Known Member

  3. Sydney99

    Sydney99 Well-Known Member

    So this will need to be reapplied after every kernel flash?
  4. Hawker

    Hawker Well-Known Member

    No butty, its an omission of the ROM itself. You will only need to run this after you flash a new ROM.
    Sydney99 likes this.
  5. suparuss

    suparuss Well-Known Member Contributor

    Hi Hawker,

    this looks great. Forgive me for being a newb but what benefit will this give?

    Is it risky? I am currently running AndyX ROM ICS and don't want to brick as I'm in the US on business and wouldn't be able to restore
  6. Hawker

    Hawker Well-Known Member

    Included some background information in post #1 that may clear things up.

    Only question mark in your case is if the zipalign program is compatible, as you are on a leaked ICS ROM.
    suparuss likes this.
  7. suparuss

    suparuss Well-Known Member Contributor

    Thanks Hawker, I understand a bit better now.

    I think then I'll wait a couple of days - when an official ICS build is released, in theory it would be possible to get that ZipAlign apk and that would be more likely to work?

Share This Page