In my build.gradle
file, I have the following:
applicationVariants.all { variant ->
def oldFile;
if (variant.zipAlign) {
oldFile = variant.outputFile;
} else {
oldFile = variant.packageApplication.outputFile;
}
def newFile;
def newFileReplacement = "";
if (getVersionName().indexOf(gitSha()) != -1) {
newFileReplacement = newFileReplacement + "-" + getVersionName() + ".apk";
} else {
newFileReplacement = newFileReplacement + "-" + getVersionName() + "-" + gitSha() + ".apk"
}
newFile = oldFile.name.replace(".apk", newFileReplacement);
if (variant.zipAlign) {
variant.zipAlign.outputFile = new File(oldFile.parent, newFile);
} else {
variant.packageApplication.outputFile = new File(oldFile.parent, newFile);
}
}
When I run the following command: ./gradlew clean assembleRelease
, it creates the following .apk files for me:
MyApp-release-1.2.3-e1ad453.apk
MyApp-release-unaligned.apk
(MyApp-release-1.2.3-e1ad453.apk
is zipaligned, but the other one is not)
What I want it to create are the following files:
MyApp-release-1.2.3-e1ad453-unaligned.apk
MyApp-release-1.2.3-e1ad453.apk
Where MyApp-release-1.2.3-e1ad453-unaligned.apk
is not zip aligned, and MyApp-release-1.2.3-e1ad453.apk
is zip aligned, since that seems to be the way that gradle operates by default (i.e. it adds to the name of the file that isn't aligned, rather than adding to the name of the file that is).
Basically, what appears to be happening is that the rename functionality operates before files are actually created, and just specifies the output file I supposedly want. This is fine, but is it possible to also specify what I want the intermediate file MyApp-release-unsigned.apk
to be before zipAlign runs?