summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Achtelik <mike.achtelik@gmail.com>2021-04-14 14:26:42 +0200
committerMike Achtelik <mike.achtelik@gmail.com>2021-05-12 10:09:17 +0200
commit08d8c5962930b8bf64d696e07ef65fb0c4871474 (patch)
treebca4d68381805407ee0f56bd9a1661bfab10c2a7 /src
parent7c233d4034237e268a513741ce69a0cd6ef47519 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/tools/androiddeployqt/main.cpp60
1 files changed, 42 insertions, 18 deletions
diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp
index 2d660ff844..4a476cd065 100644
--- a/src/tools/androiddeployqt/main.cpp
+++ b/src/tools/androiddeployqt/main.cpp
@@ -2788,28 +2788,52 @@ bool signPackage(const Options &options)
}
}
- zipAlignTool = QLatin1String("%1%2 -f 4 %3 %4")
+ auto zipalignRunner = [](const QString &zipAlignCommandLine) {
+ FILE *zipAlignCommand = openProcess(zipAlignCommandLine);
+ if (zipAlignCommand == 0) {
+ fprintf(stderr, "Couldn't run zipalign.\n");
+ return false;
+ }
+
+ char buffer[512];
+ while (fgets(buffer, sizeof(buffer), zipAlignCommand) != 0)
+ fprintf(stdout, "%s", buffer);
+
+ return pclose(zipAlignCommand) == 0;
+ };
+
+ const QString verifyZipAlignCommandLine = QLatin1String("%1%2 -c 4 %3")
.arg(shellQuote(zipAlignTool),
options.verbose ? QLatin1String(" -v") : QLatin1String(),
- packagePath(options, UnsignedAPK),
- packagePath(options, SignedAPK));
+ packagePath(options, UnsignedAPK));
- FILE *zipAlignCommand = openProcess(zipAlignTool);
- if (zipAlignCommand == 0) {
- fprintf(stderr, "Couldn't run zipalign.\n");
- return false;
- }
+ if (zipalignRunner(verifyZipAlignCommandLine)) {
+ if (options.verbose)
+ fprintf(stdout, "APK already aligned, copying it for signing.\n");
- char buffer[512];
- while (fgets(buffer, sizeof(buffer), zipAlignCommand) != 0)
- fprintf(stdout, "%s", buffer);
+ if (QFile::exists(packagePath(options, SignedAPK)))
+ QFile::remove(packagePath(options, SignedAPK));
- int errorCode = pclose(zipAlignCommand);
- if (errorCode != 0) {
- fprintf(stderr, "zipalign command failed.\n");
- if (!options.verbose)
- fprintf(stderr, " -- Run with --verbose for more information.\n");
- return false;
+ 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")
@@ -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)