Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APK compression level, size reduction

Tags:

android

apk

Since an APK file is just a Zip file with a different extension and a few meta parameters, it seems that there is a way to change the compression level of the file.

Just to verify that Eclipse isn't exporting with the highest compression level, I've tried to pack the contents of the APK on my own with the compression level set to via winrar, and I got a reduction of 20% which
about 1 MB.

I couldn't find any easy way to repack the APK safely without deleting the metadata. I've tried with 7zip , aapt, apktool.

like image 629
Kirill Kulakov Avatar asked Oct 22 '22 03:10

Kirill Kulakov


1 Answers

You can use the following ant task to repack apk:

<target name="-post-package">
<exec executable="${z7zip}">
  <arg value="x"/>
  <arg value="-o${out.dir}/TempApk"/>
  <arg value="${out.packaged.file}"/>
</exec>
<delete file="${out.packaged.file}" verbose="${verbose}"/>
<exec executable="${z7zip}" dir="${out.dir}/TempApk">
  <arg value="a"/>
  <arg value="-tzip"/>
  <arg value="-mx9"/>
  <arg value="-r"/>
  <arg value="${out.packaged.file}"/>
  <arg value="*.*"/>
</exec>
<delete dir="${out.dir}/TempApk" verbose="${verbose}" />

It uses 7zip. Path to 7zip should be in the local.properties:

z7zip=C:\\Program Files\\7-Zip\\7z.exe

It gives about 15% better compression. Of course you can use any other tool or just execute these command lines manually to repack your apk.

like image 78
Dmitry Kochin Avatar answered Oct 24 '22 10:10

Dmitry Kochin