Yes, you can reduce the size of an APK file by just changing its compression.
You can use any ZIP utility, such as WinZip, WinRAR, or 7-Zip. I used 7-Zip.
To execute these commands, I created a .BAT script, but here I explain step-by-step script lines (my APK file is C:\Android\Teste.apk
).
First make sure that the temporary folder used in the process is empty, in my case C:\Android\TempAPK
:
if exist C:\Android\TempAPK (
del /S /Q C:\Android\TempAPK
rd /S /Q C:\Android\TempAPK
)
md C:\Android\TempAPK
Then, I extract the content of the APK to this temporary folder:
"C:\Program Files-Zipz.exe" x C:\Android\Teste.apk -oC:\Android\TempAPK
Next, you should exclude the folder META-INF
, along with its content (I did not use the deltree
command because I did not find it in Windows 8):
del C:\Android\TempAPK\META-INF /S /Q
rd C:\Android\TempAPK\META-INF
Then, I compress the files again to a file named Teste.zip
using the Deflate
method (this is MANDATORY ), and with the compression settings to the maximum:
cd C:\Android
"C:\Program Files-Zipz.exe" a -tzip C:\Android\Teste.zip .\TempAPK\* -mm=Deflate -mpass=15 -mfb=258
Now you need to sign this ZIP, using the jarsigner
tool, which comes with JDK (in my case, it is JDK 1.7.0_10):
cd "C:\Program Files\Java\jdk1.7.0_10\bin"
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore C:\Android\keystore\keystore.bin -storepass <SENHA DA KEYSTORE> -keypass <SENHA DA KEY> C:\Android\Teste.zip <ALIAS DA KEY>
Now just align the ZIP file using the zipalign
tool, creating the final APK, and clear all temporary files (note the path of the SDK):
cd C:\Android\sdk\build-tools\android-4.4W
del C:\Android\Teste.apk
zipalign 4 C:\Android\Teste.zip C:\Android\Teste.apk
del /S /Q C:\Android\TempAPK
rd /S /Q C:\Android\TempAPK
del C:\Android\Teste.zip
This reduced the size of my APK from 330kB to 274kB.
More about signing on the Google website:
Signing Your Applications
Building and Running from the Command Line