Zipalign implemented in java without any dependencies. Read my post about it :>
Pass in a RandomAccessFile
to the function ZipAlign#alignZip
to provide ZipAlign with a seekable file for more performant aligning.
import com.iyxan23.zipalignjava.ZipAlign;
RandomAccessFile zipIn = new RandomAccessFile(zipPath, "r");
FileOutputStream zipOut = ...;
ZipAlign.alignZip(zipIn, zipOut);
Additionaly, you could use a regular InputStream
.
import com.iyxan23.zipalignjava.ZipAlign;
FileInputStream zipIn = ...;
FileOutputStream zipOut = ...;
ZipAlign.alignZip(zipIn, zipOut);
Aligning .so files to 4KiB page boundaries are enabled by default, pass in a boolean to opt out:
ZipAlign.alignZip(zipIn, zipOut, false);
This library is published in jitpack, you can add it as your dependency it with:
allprojects {
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation 'com.github.iyxan23:zipalign-java:1.1.1'
}
You could also use prebuilt jars by the CI or in the releases section.
The jar contains a simple CLI that allows you to use it in the command line.
$ java -jar zipalign-java-1.1.1.jar input.zip output.zip
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 --