Zipalign implemented in java with 0 dependencies.
Note: zip64 is currently unsupported, this may not work on apks with the size bigger than 4GB.
It is highly recommended to use a RandomAccessFile
as the zip input.
import com.iyxan23.zipalignjava.ZipAlign;
RandomAccessFile zipIn = new RandomAccessFile(zipPath, "r");
FileOutputStream zipOut = ...;
ZipAlign.alignZip(zipIn, zipOut);
or if you really need it, you can read from an InputStream
. Do note that this is substantially slower than using RandomAccessFile
.
import com.iyxan23.zipalignjava.ZipAlign;
FileInputStream zipIn = ...;
FileOutputStream zipOut = ...;
ZipAlign.alignZip(zipIn, zipOut);
You can use this library by importing this as a gradle module to your project, building a jar, or just by copying the classes.
To build a jar, run:
$ ./gradlew jar
and you'll have a built jar in the build/libs
directory.
This jar will contain a very simple cli that allows you to run it in your command line.
$ java -jar zipalign-java-0.1-dev.jar input.zip output.zip
These benchmarks are ran on an AMD Ryzen 5-5500U CPU with IntelliJ IDEA's runner and Temurin JDK 18.
Function Avg elapsed time Input
ZipAlign#alignZip(RandomAccessFile, OutputStream) 28ms File from https://github.com/Iyxan23/zipalign-java/issues/1#issue-1236875761 (270K)
ZipAlign#alignZip(InputStream, OutputStream) 497ms -- same file --