Add support for aab
Change-Id: I4814a51b25d5e3953e5e1c71d9a0e1bf3fed7385 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
60bea1c85a
commit
c9f8893000
@ -121,8 +121,8 @@ struct Options
|
|||||||
, auxMode(false)
|
, auxMode(false)
|
||||||
, deploymentMechanism(Bundled)
|
, deploymentMechanism(Bundled)
|
||||||
, releasePackage(false)
|
, releasePackage(false)
|
||||||
, digestAlg(QLatin1String("SHA1"))
|
, digestAlg(QLatin1String("SHA-256"))
|
||||||
, sigAlg(QLatin1String("SHA1withRSA"))
|
, sigAlg(QLatin1String("SHA256withRSA"))
|
||||||
, internalSf(false)
|
, internalSf(false)
|
||||||
, sectionsOnly(false)
|
, sectionsOnly(false)
|
||||||
, protectedAuthenticationPath(false)
|
, protectedAuthenticationPath(false)
|
||||||
@ -181,6 +181,8 @@ struct Options
|
|||||||
QString currentArchitecture;
|
QString currentArchitecture;
|
||||||
QString toolchainPrefix;
|
QString toolchainPrefix;
|
||||||
QString ndkHost;
|
QString ndkHost;
|
||||||
|
bool buildAAB = false;
|
||||||
|
|
||||||
|
|
||||||
// Package information
|
// Package information
|
||||||
DeploymentMechanism deploymentMechanism;
|
DeploymentMechanism deploymentMechanism;
|
||||||
@ -412,7 +414,10 @@ Options parseOptions()
|
|||||||
options.helpRequested = true;
|
options.helpRequested = true;
|
||||||
else
|
else
|
||||||
options.inputFileName = arguments.at(++i);
|
options.inputFileName = arguments.at(++i);
|
||||||
} else if (argument.compare(QLatin1String("--no-build"), Qt::CaseInsensitive) == 0) {
|
} else if (argument.compare(QLatin1String("--aab"), Qt::CaseInsensitive) == 0) {
|
||||||
|
options.buildAAB = true;
|
||||||
|
options.build = true;
|
||||||
|
} else if (options.buildAAB && argument.compare(QLatin1String("--no-build"), Qt::CaseInsensitive) == 0) {
|
||||||
options.build = false;
|
options.build = false;
|
||||||
} else if (argument.compare(QLatin1String("--install"), Qt::CaseInsensitive) == 0) {
|
} else if (argument.compare(QLatin1String("--install"), Qt::CaseInsensitive) == 0) {
|
||||||
options.installApk = true;
|
options.installApk = true;
|
||||||
@ -553,6 +558,7 @@ void printHelp()
|
|||||||
" --deployment <mechanism>: Supported deployment mechanisms:\n"
|
" --deployment <mechanism>: Supported deployment mechanisms:\n"
|
||||||
" bundled (default): Include Qt files in stand-alone package.\n"
|
" bundled (default): Include Qt files in stand-alone package.\n"
|
||||||
" ministro: Use the Ministro service to manage Qt files.\n"
|
" ministro: Use the Ministro service to manage Qt files.\n"
|
||||||
|
" --aab: Build an Android App Bundle.\n"
|
||||||
" --no-build: Do not build the package, it is useful to just install\n"
|
" --no-build: Do not build the package, it is useful to just install\n"
|
||||||
" a package previously built.\n"
|
" a package previously built.\n"
|
||||||
" --install: Installs apk to device/emulator. By default this step is\n"
|
" --install: Installs apk to device/emulator. By default this step is\n"
|
||||||
@ -2272,6 +2278,9 @@ bool buildAndroidProject(const Options &options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString commandLine = QLatin1String("%1 --no-daemon %2").arg(shellQuote(gradlePath), options.releasePackage ? QLatin1String(" assembleRelease") : QLatin1String(" assembleDebug"));
|
QString commandLine = QLatin1String("%1 --no-daemon %2").arg(shellQuote(gradlePath), options.releasePackage ? QLatin1String(" assembleRelease") : QLatin1String(" assembleDebug"));
|
||||||
|
if (options.buildAAB)
|
||||||
|
commandLine += QLatin1String(" bundle");
|
||||||
|
|
||||||
if (options.verbose)
|
if (options.verbose)
|
||||||
commandLine += QLatin1String(" --info");
|
commandLine += QLatin1String(" --info");
|
||||||
|
|
||||||
@ -2332,28 +2341,38 @@ bool uninstallApk(const Options &options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum PackageType {
|
enum PackageType {
|
||||||
|
AAB,
|
||||||
UnsignedAPK,
|
UnsignedAPK,
|
||||||
SignedAPK
|
SignedAPK
|
||||||
};
|
};
|
||||||
|
|
||||||
QString apkPath(const Options &options, PackageType pt)
|
QString packagePath(const Options &options, PackageType pt)
|
||||||
{
|
{
|
||||||
QString path(options.outputDirectory);
|
QString path(options.outputDirectory);
|
||||||
path += QLatin1String("/build/outputs/apk/");
|
path += QLatin1String("/build/outputs/%1/").arg(pt >= UnsignedAPK ? QStringLiteral("apk") : QStringLiteral("bundle"));
|
||||||
QString buildType(options.releasePackage ? QLatin1String("release/") : QLatin1String("debug/"));
|
QString buildType(options.releasePackage ? QLatin1String("release/") : QLatin1String("debug/"));
|
||||||
if (QDir(path + buildType).exists())
|
if (QDir(path + buildType).exists())
|
||||||
path += buildType;
|
path += buildType;
|
||||||
path += QDir(options.outputDirectory).dirName() + QLatin1Char('-');
|
path += QDir(options.outputDirectory).dirName() + QLatin1Char('-');
|
||||||
if (options.releasePackage) {
|
if (options.releasePackage) {
|
||||||
path += QLatin1String("release-");
|
path += QLatin1String("release-");
|
||||||
|
if (pt >= UnsignedAPK) {
|
||||||
if (pt == UnsignedAPK)
|
if (pt == UnsignedAPK)
|
||||||
path += QLatin1String("un");
|
path += QLatin1String("un");
|
||||||
path += QLatin1String("signed.apk");
|
path += QLatin1String("signed.apk");
|
||||||
|
} else {
|
||||||
|
path.chop(1);
|
||||||
|
path += QLatin1String(".aab");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
path += QLatin1String("debug");
|
path += QLatin1String("debug");
|
||||||
|
if (pt >= UnsignedAPK) {
|
||||||
if (pt == SignedAPK)
|
if (pt == SignedAPK)
|
||||||
path += QLatin1String("-signed");
|
path += QLatin1String("-signed");
|
||||||
path += QLatin1String(".apk");
|
path += QLatin1String(".apk");
|
||||||
|
} else {
|
||||||
|
path += QLatin1String(".aab");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return shellQuote(path);
|
return shellQuote(path);
|
||||||
}
|
}
|
||||||
@ -2370,7 +2389,7 @@ bool installApk(const Options &options)
|
|||||||
|
|
||||||
FILE *adbCommand = runAdb(options,
|
FILE *adbCommand = runAdb(options,
|
||||||
QLatin1String(" install -r ")
|
QLatin1String(" install -r ")
|
||||||
+ apkPath(options, options.keyStore.isEmpty() ? UnsignedAPK
|
+ packagePath(options, options.keyStore.isEmpty() ? UnsignedAPK
|
||||||
: SignedAPK));
|
: SignedAPK));
|
||||||
if (adbCommand == 0)
|
if (adbCommand == 0)
|
||||||
return false;
|
return false;
|
||||||
@ -2396,7 +2415,7 @@ bool installApk(const Options &options)
|
|||||||
bool copyPackage(const Options &options)
|
bool copyPackage(const Options &options)
|
||||||
{
|
{
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
auto from = apkPath(options, options.keyStore.isEmpty() ? UnsignedAPK : SignedAPK);
|
auto from = packagePath(options, options.keyStore.isEmpty() ? UnsignedAPK : SignedAPK);
|
||||||
QFile::remove(options.apkPath);
|
QFile::remove(options.apkPath);
|
||||||
return QFile::copy(from, options.apkPath);
|
return QFile::copy(from, options.apkPath);
|
||||||
}
|
}
|
||||||
@ -2479,11 +2498,14 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
if (options.protectedAuthenticationPath)
|
if (options.protectedAuthenticationPath)
|
||||||
jarSignerTool += QLatin1String(" -protected");
|
jarSignerTool += QLatin1String(" -protected");
|
||||||
|
|
||||||
jarSignerTool += QLatin1String(" %1 %2")
|
auto signPackage = [&](const QString &file) {
|
||||||
.arg(apkPath(options, UnsignedAPK))
|
fprintf(stdout, "Signing file %s\n", qPrintable(file));
|
||||||
|
fflush(stdout);
|
||||||
|
auto command = jarSignerTool + QLatin1String(" %1 %2")
|
||||||
|
.arg(file)
|
||||||
.arg(shellQuote(options.keyStoreAlias));
|
.arg(shellQuote(options.keyStoreAlias));
|
||||||
|
|
||||||
FILE *jarSignerCommand = openProcess(jarSignerTool);
|
FILE *jarSignerCommand = openProcess(command);
|
||||||
if (jarSignerCommand == 0) {
|
if (jarSignerCommand == 0) {
|
||||||
fprintf(stderr, "Couldn't run jarsigner.\n");
|
fprintf(stderr, "Couldn't run jarsigner.\n");
|
||||||
return false;
|
return false;
|
||||||
@ -2502,6 +2524,13 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
fprintf(stderr, " -- Run with --verbose for more information.\n");
|
fprintf(stderr, " -- Run with --verbose for more information.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!signPackage(packagePath(options, UnsignedAPK)))
|
||||||
|
return false;
|
||||||
|
if (options.buildAAB && !signPackage(packagePath(options, AAB)))
|
||||||
|
return false;
|
||||||
|
|
||||||
QString zipAlignTool = options.sdkPath + QLatin1String("/tools/zipalign");
|
QString zipAlignTool = options.sdkPath + QLatin1String("/tools/zipalign");
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
@ -2522,8 +2551,8 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
zipAlignTool = QLatin1String("%1%2 -f 4 %3 %4")
|
zipAlignTool = QLatin1String("%1%2 -f 4 %3 %4")
|
||||||
.arg(shellQuote(zipAlignTool),
|
.arg(shellQuote(zipAlignTool),
|
||||||
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
||||||
apkPath(options, UnsignedAPK),
|
packagePath(options, UnsignedAPK),
|
||||||
apkPath(options, SignedAPK));
|
packagePath(options, SignedAPK));
|
||||||
|
|
||||||
FILE *zipAlignCommand = openProcess(zipAlignTool);
|
FILE *zipAlignCommand = openProcess(zipAlignTool);
|
||||||
if (zipAlignCommand == 0) {
|
if (zipAlignCommand == 0) {
|
||||||
@ -2535,7 +2564,7 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
while (fgets(buffer, sizeof(buffer), zipAlignCommand) != 0)
|
while (fgets(buffer, sizeof(buffer), zipAlignCommand) != 0)
|
||||||
fprintf(stdout, "%s", buffer);
|
fprintf(stdout, "%s", buffer);
|
||||||
|
|
||||||
errorCode = pclose(zipAlignCommand);
|
int errorCode = pclose(zipAlignCommand);
|
||||||
if (errorCode != 0) {
|
if (errorCode != 0) {
|
||||||
fprintf(stderr, "zipalign command failed.\n");
|
fprintf(stderr, "zipalign command failed.\n");
|
||||||
if (!options.verbose)
|
if (!options.verbose)
|
||||||
@ -2543,7 +2572,7 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QFile::remove(apkPath(options, UnsignedAPK));
|
return QFile::remove(packagePath(options, UnsignedAPK));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool signPackage(const Options &options)
|
bool signPackage(const Options &options)
|
||||||
@ -2577,8 +2606,8 @@ bool signPackage(const Options &options)
|
|||||||
zipAlignTool = QLatin1String("%1%2 -f 4 %3 %4")
|
zipAlignTool = QLatin1String("%1%2 -f 4 %3 %4")
|
||||||
.arg(shellQuote(zipAlignTool),
|
.arg(shellQuote(zipAlignTool),
|
||||||
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
options.verbose ? QLatin1String(" -v") : QLatin1String(),
|
||||||
apkPath(options, UnsignedAPK),
|
packagePath(options, UnsignedAPK),
|
||||||
apkPath(options, SignedAPK));
|
packagePath(options, SignedAPK));
|
||||||
|
|
||||||
FILE *zipAlignCommand = openProcess(zipAlignTool);
|
FILE *zipAlignCommand = openProcess(zipAlignTool);
|
||||||
if (zipAlignCommand == 0) {
|
if (zipAlignCommand == 0) {
|
||||||
@ -2614,7 +2643,7 @@ bool signPackage(const Options &options)
|
|||||||
apkSignerCommandLine += QLatin1String(" --verbose");
|
apkSignerCommandLine += QLatin1String(" --verbose");
|
||||||
|
|
||||||
apkSignerCommandLine += QLatin1String(" %1")
|
apkSignerCommandLine += QLatin1String(" %1")
|
||||||
.arg(apkPath(options, SignedAPK));
|
.arg(packagePath(options, SignedAPK));
|
||||||
|
|
||||||
auto apkSignerRunner = [&] {
|
auto apkSignerRunner = [&] {
|
||||||
FILE *apkSignerCommand = openProcess(apkSignerCommandLine);
|
FILE *apkSignerCommand = openProcess(apkSignerCommandLine);
|
||||||
@ -2642,10 +2671,10 @@ bool signPackage(const Options &options)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
apkSignerCommandLine = QLatin1String("%1 verify --verbose %2")
|
apkSignerCommandLine = QLatin1String("%1 verify --verbose %2")
|
||||||
.arg(shellQuote(apksignerTool), apkPath(options, SignedAPK));
|
.arg(shellQuote(apksignerTool), packagePath(options, SignedAPK));
|
||||||
|
|
||||||
// Verify the package and remove the unsigned apk
|
// Verify the package and remove the unsigned apk
|
||||||
return apkSignerRunner() && QFile::remove(apkPath(options, UnsignedAPK));
|
return apkSignerRunner() && QFile::remove(packagePath(options, UnsignedAPK));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool generateAssetsFileList(const Options &options)
|
bool generateAssetsFileList(const Options &options)
|
||||||
@ -2869,7 +2898,7 @@ int main(int argc, char *argv[])
|
|||||||
if (options.installApk)
|
if (options.installApk)
|
||||||
fprintf(stdout, " -- It can now be run from the selected device/emulator.\n");
|
fprintf(stdout, " -- It can now be run from the selected device/emulator.\n");
|
||||||
|
|
||||||
fprintf(stdout, " -- File: %s\n", qPrintable(apkPath(options, options.keyStore.isEmpty() ? UnsignedAPK
|
fprintf(stdout, " -- File: %s\n", qPrintable(packagePath(options, options.keyStore.isEmpty() ? UnsignedAPK
|
||||||
: SignedAPK)));
|
: SignedAPK)));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user