androiddeployqt: Check if apk is already aligned
Newer versions of the android gradle plugin already align the apk internally. Therefore it is not necessary to indiscriminately align every apk. So let's first check, if it is already aligned and only align it if necessary. This prevents possible alignment errors, which might occur when aligning it again. If it is already aligned, we can just copy and continue signing the apk. Fixes: QTBUG-88989 Change-Id: If29004e372e7927c88a900dc56f490bf9bce9ec7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
7c233d4034
commit
08d8c59629
@ -2788,13 +2788,8 @@ bool signPackage(const Options &options)
|
||||
}
|
||||
}
|
||||
|
||||
zipAlignTool = QLatin1String("%1%2 -f 4 %3 %4")
|
||||
.arg(shellQuote(zipAlignTool),
|
||||
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
||||
packagePath(options, UnsignedAPK),
|
||||
packagePath(options, SignedAPK));
|
||||
|
||||
FILE *zipAlignCommand = openProcess(zipAlignTool);
|
||||
auto zipalignRunner = [](const QString &zipAlignCommandLine) {
|
||||
FILE *zipAlignCommand = openProcess(zipAlignCommandLine);
|
||||
if (zipAlignCommand == 0) {
|
||||
fprintf(stderr, "Couldn't run zipalign.\n");
|
||||
return false;
|
||||
@ -2804,13 +2799,42 @@ bool signPackage(const Options &options)
|
||||
while (fgets(buffer, sizeof(buffer), zipAlignCommand) != 0)
|
||||
fprintf(stdout, "%s", buffer);
|
||||
|
||||
int errorCode = pclose(zipAlignCommand);
|
||||
if (errorCode != 0) {
|
||||
return pclose(zipAlignCommand) == 0;
|
||||
};
|
||||
|
||||
const QString verifyZipAlignCommandLine = QLatin1String("%1%2 -c 4 %3")
|
||||
.arg(shellQuote(zipAlignTool),
|
||||
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
||||
packagePath(options, UnsignedAPK));
|
||||
|
||||
if (zipalignRunner(verifyZipAlignCommandLine)) {
|
||||
if (options.verbose)
|
||||
fprintf(stdout, "APK already aligned, copying it for signing.\n");
|
||||
|
||||
if (QFile::exists(packagePath(options, SignedAPK)))
|
||||
QFile::remove(packagePath(options, SignedAPK));
|
||||
|
||||
if (!QFile::copy(packagePath(options, UnsignedAPK), packagePath(options, SignedAPK))) {
|
||||
fprintf(stderr, "Could not copy unsigned APK.\n");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (options.verbose)
|
||||
fprintf(stdout, "APK not aligned, aligning it for signing.\n");
|
||||
|
||||
const QString zipAlignCommandLine = QLatin1String("%1%2 -f 4 %3 %4")
|
||||
.arg(shellQuote(zipAlignTool),
|
||||
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
||||
packagePath(options, UnsignedAPK),
|
||||
packagePath(options, SignedAPK));
|
||||
|
||||
if (!zipalignRunner(zipAlignCommandLine)) {
|
||||
fprintf(stderr, "zipalign command failed.\n");
|
||||
if (!options.verbose)
|
||||
fprintf(stderr, " -- Run with --verbose for more information.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QString apkSignerCommandLine = QLatin1String("%1 sign --ks %2")
|
||||
.arg(shellQuote(apksignerTool), shellQuote(options.keyStore));
|
||||
@ -2841,7 +2865,7 @@ bool signPackage(const Options &options)
|
||||
while (fgets(buffer, sizeof(buffer), apkSignerCommand) != 0)
|
||||
fprintf(stdout, "%s", buffer);
|
||||
|
||||
errorCode = pclose(apkSignerCommand);
|
||||
int errorCode = pclose(apkSignerCommand);
|
||||
if (errorCode != 0) {
|
||||
fprintf(stderr, "apksigner command failed.\n");
|
||||
if (!options.verbose)
|
||||
|
Loading…
x
Reference in New Issue
Block a user