# [UTILITY]Zip Align in Windows



## imnuts (Jun 9, 2011)

I don't know how many other people work in Windows frequently, but I do, and I wanted to zip align files in a ROM before packaging it for release. I couldn't find an easy method to do this posted anywhere else, so I created one. Here is a batch file that you can place in a folder, and it will go through the directory and sub-directories and zip align all apk files that are found. It's fairly simple, and I haven't seen any issues with it in my limited testing, but anything could happen, so you may want to keep a backup just in case. I posted it on Github, but will post the code here as well for anyone that may want it. Just copy and paste the below into a file with the extension of *.bat. Also, zipalign will need to be in your Windows $PATH for this to work properly. Hopefully, if you're using this, you can figure out how to do that, if not, you should before you use it.

```
@echo off<br />
REM Batch file to recursively zip align *.apk files in a directory<br />
REM and its sub-directories. This is significantly easier and faster<br />
REM than manually zip aligning them.<br />
@echo Zip aligning now...<br />
for /R %%X in (*.apk) do zipalign 4 "%%X" "%%~dpX%%~nX.new"<br />
@echo Replacing non-aligned files with zip aligned files...<br />
for /R %%X in (*.new) do move /Y "%%X" "%%~dpX%%~nX.apk"<br />
@echo Zip aligning done, press any key to exit<br />
pause
```


----------



## DrMacinyasha (Jun 6, 2011)

Nifty. Thanks for this.


----------



## imnuts (Jun 9, 2011)

DrMacinyasha said:


> Nifty. Thanks for this.


No problem. Not that zip aligning does to much, but I feel if it were simple, people may actually use it more often. I may try to make one for Linux/Unix then as well, since there are likely significantly more people doing work in Linux compared to Windows.


----------



## Formula84 (Oct 5, 2011)

Just wanted to say thanks, I was using APK multitool and it was failing on zipalign even with SDK installed...I tried this and it was failing as well even with zip align copied to windows and system32...so i copied it to the folder i was calling the bat from and it worked great...FWIW I am on windows 7 SP1 x64 with UAC turned off.


----------



## TommyB231 (Mar 4, 2012)

Thanks OP! This is more important than you think. In HTC Sense 4 and ICS, if you modify even uncompressed, compiled resources using 7zip on WorldClock.apk and don't zipalign, it force closes!


----------

