Android: Refactor packagePath() in androiddeployqt

Make the method handle all the different possible
paths in a more clean way.

Task-number: QTBUG-116955
Task-number: QTBUG-65567
Change-Id: If0ed1b529011b942c0fb67d0ad7a940896e03c85
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Soheil Armin 2024-04-25 16:26:38 +03:00 committed by Tinja Paavoseppä
parent 79f3fe7040
commit 28b3848989

View File

@ -2972,47 +2972,38 @@ enum PackageType {
SignedAPK SignedAPK
}; };
QString packagePath(const Options &options, PackageType pt) QString packagePath(const Options &options, PackageType packageType)
{ {
QString path(options.outputDirectory);
// The package type is always AAR if option.buildAar has been set // The package type is always AAR if option.buildAar has been set
if (options.buildAar) if (options.buildAar)
pt = AAR; packageType = AAR;
static QHash<PackageType, QString> packageTypeToPath{ { AAB, QStringLiteral("bundle") },
{ AAR, QStringLiteral("aar") }, static const QHash<PackageType, QLatin1StringView> packageTypeToPath{
{ UnsignedAPK, QStringLiteral("apk") }, { AAB, "bundle"_L1 }, { AAR, "aar"_L1 }, { UnsignedAPK, "apk"_L1 }, { SignedAPK, "apk"_L1 }
{ SignedAPK, QStringLiteral("apk") } }; };
path += "/build/outputs/%1/"_L1.arg(packageTypeToPath[pt]); static const QHash<PackageType, QLatin1StringView> packageTypeToExtension{
QString buildType(options.releasePackage ? "release/"_L1 : "debug/"_L1); { AAB, "aab"_L1 }, { AAR, "aar"_L1 }, { UnsignedAPK, "apk"_L1 }, { SignedAPK, "apk"_L1 }
if (QDir(path + buildType).exists()) };
path += buildType;
path += QDir(options.outputDirectory).dirName() + u'-'; const QString buildType(options.releasePackage ? "release"_L1 : "debug"_L1);
if (options.releasePackage) { QString signedSuffix;
path += "release-"_L1; if (packageType == SignedAPK)
if (pt >= UnsignedAPK) { signedSuffix = "-signed"_L1;
if (pt == UnsignedAPK) else if (packageType == UnsignedAPK && options.releasePackage)
path += "un"_L1; signedSuffix = "-unsigned"_L1;
path += "signed.apk"_L1;
} else if (pt == AAR){ QString dirPath(options.outputDirectory);
path.chop(1); dirPath += "/build/outputs/%1/"_L1.arg(packageTypeToPath[packageType]);
path += ".aar"_L1; if (QDir(dirPath + buildType).exists())
} else { dirPath += buildType;
path.chop(1);
path += ".aab"_L1; const QString fileName = "/%1-%2%3.%4"_L1.arg(
} QDir(options.outputDirectory).dirName(),
} else { buildType,
path += "debug"_L1; signedSuffix,
if (pt >= UnsignedAPK) { packageTypeToExtension[packageType]);
if (pt == SignedAPK)
path += "-signed"_L1; return dirPath + fileName;
path += ".apk"_L1;
} else if (pt == AAR){
path += ".aar"_L1;
} else {
path += ".aab"_L1;
}
}
return path;
} }
bool installApk(const Options &options) bool installApk(const Options &options)