APK compression level, size reduction

Since the APK file is only a Zip file with a different extension and several meta options, it seems that there is a way to change the file compression level.

To make sure that Eclipse does not export with the highest compression level, I tried to pack the contents of the APK myself with the compression level set with winrar, and I got a 20% reduction, which
about 1 MB.

I could not find an easy way to repackage the APK safely without deleting the metadata. I tried with 7zip, aapt, apktool.

+4
source share
1 answer

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. The path to 7zip should be in local.properties:

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

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

+3
source

Source: https://habr.com/ru/post/1495882/


All Articles