Android: Nuke ant support
Ant is history for so many years, yet we forgot to remove it from androiddeployqt. [ChangeLog][Android] Remove ant support from androiddeployqt Change-Id: I093295e18e8710c565e9d101e21c49b3c62f6322 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
a5e03f59f4
commit
0ad4da0c64
@ -118,7 +118,6 @@ struct Options
|
|||||||
, timing(false)
|
, timing(false)
|
||||||
, generateAssetsFileList(true)
|
, generateAssetsFileList(true)
|
||||||
, build(true)
|
, build(true)
|
||||||
, gradle(false)
|
|
||||||
, auxMode(false)
|
, auxMode(false)
|
||||||
, deploymentMechanism(Bundled)
|
, deploymentMechanism(Bundled)
|
||||||
, releasePackage(false)
|
, releasePackage(false)
|
||||||
@ -150,7 +149,6 @@ struct Options
|
|||||||
bool timing;
|
bool timing;
|
||||||
bool generateAssetsFileList;
|
bool generateAssetsFileList;
|
||||||
bool build;
|
bool build;
|
||||||
bool gradle;
|
|
||||||
bool auxMode;
|
bool auxMode;
|
||||||
bool stripLibraries = true;
|
bool stripLibraries = true;
|
||||||
ActionTimer timer;
|
ActionTimer timer;
|
||||||
@ -159,7 +157,6 @@ struct Options
|
|||||||
QString sdkPath;
|
QString sdkPath;
|
||||||
QString sdkBuildToolsVersion;
|
QString sdkBuildToolsVersion;
|
||||||
QString ndkPath;
|
QString ndkPath;
|
||||||
QString antTool;
|
|
||||||
QString jdkPath;
|
QString jdkPath;
|
||||||
|
|
||||||
// Build paths
|
// Build paths
|
||||||
@ -369,13 +366,6 @@ Options parseOptions()
|
|||||||
options.helpRequested = true;
|
options.helpRequested = true;
|
||||||
} else if (argument.compare(QLatin1String("--verbose"), Qt::CaseInsensitive) == 0) {
|
} else if (argument.compare(QLatin1String("--verbose"), Qt::CaseInsensitive) == 0) {
|
||||||
options.verbose = true;
|
options.verbose = true;
|
||||||
} else if (argument.compare(QLatin1String("--gradle"), Qt::CaseInsensitive) == 0) {
|
|
||||||
options.gradle = true;
|
|
||||||
} else if (argument.compare(QLatin1String("--ant"), Qt::CaseInsensitive) == 0) {
|
|
||||||
if (i + 1 == arguments.size())
|
|
||||||
options.helpRequested = true;
|
|
||||||
else
|
|
||||||
options.antTool = arguments.at(++i);
|
|
||||||
} else if (argument.compare(QLatin1String("--deployment"), Qt::CaseInsensitive) == 0) {
|
} else if (argument.compare(QLatin1String("--deployment"), Qt::CaseInsensitive) == 0) {
|
||||||
if (i + 1 == arguments.size()) {
|
if (i + 1 == arguments.size()) {
|
||||||
options.helpRequested = true;
|
options.helpRequested = true;
|
||||||
@ -515,9 +505,6 @@ void printHelp()
|
|||||||
" --android-platform <platform>: Builds against the given android\n"
|
" --android-platform <platform>: Builds against the given android\n"
|
||||||
" platform. By default, the highest available version will be\n"
|
" platform. By default, the highest available version will be\n"
|
||||||
" used.\n"
|
" used.\n"
|
||||||
" --gradle. Use gradle instead of ant to create and install the apk.\n"
|
|
||||||
" --ant <path/to/ant>: If unspecified, ant from the PATH will be\n"
|
|
||||||
" used.\n"
|
|
||||||
" --release: Builds a package ready for release. By default, the\n"
|
" --release: Builds a package ready for release. By default, the\n"
|
||||||
" package will be signed with a debug key.\n"
|
" package will be signed with a debug key.\n"
|
||||||
" --sign <url/to/keystore> <alias>: Signs the package with the\n"
|
" --sign <url/to/keystore> <alias>: Signs the package with the\n"
|
||||||
@ -1024,16 +1011,13 @@ bool copyAndroidTemplate(const Options &options)
|
|||||||
if (options.verbose)
|
if (options.verbose)
|
||||||
fprintf(stdout, "Copying Android package template.\n");
|
fprintf(stdout, "Copying Android package template.\n");
|
||||||
|
|
||||||
if (options.gradle && !copyGradleTemplate(options))
|
if (!copyGradleTemplate(options))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!copyAndroidTemplate(options, QLatin1String("/src/android/templates")))
|
if (!copyAndroidTemplate(options, QLatin1String("/src/android/templates")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (options.gradle)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return copyAndroidTemplate(options, QLatin1String("/src/android/java"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool copyAndroidSources(const Options &options)
|
bool copyAndroidSources(const Options &options)
|
||||||
@ -1282,36 +1266,6 @@ bool updateStringsXml(const Options &options)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!updateFile(fileName, replacements))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (options.gradle)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// ant can't (easily) build multiple res folders,
|
|
||||||
// so we need to replace the "<!-- %%INSERT_STRINGS -->" placeholder
|
|
||||||
// from the main res folder
|
|
||||||
QFile stringsXml(fileName);
|
|
||||||
if (!stringsXml.open(QIODevice::ReadOnly)) {
|
|
||||||
fprintf(stderr, "Cannot open %s for reading.\n", qPrintable(fileName));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QXmlStreamReader reader(&stringsXml);
|
|
||||||
while (!reader.atEnd()) {
|
|
||||||
reader.readNext();
|
|
||||||
if (reader.isStartElement() &&
|
|
||||||
reader.name() == QLatin1String("string") &&
|
|
||||||
reader.attributes().hasAttribute(QLatin1String("name")) &&
|
|
||||||
reader.attributes().value(QLatin1String("name")) == QLatin1String("app_name")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
replacements.clear();
|
|
||||||
replacements[QStringLiteral("<!-- %%INSERT_STRINGS -->")] = QString::fromLatin1("<string name=\"app_name\">%1</string>\n")
|
|
||||||
.arg(QFileInfo(options.applicationBinary).baseName().mid(sizeof("lib") - 1));
|
|
||||||
|
|
||||||
if (!updateFile(fileName, replacements))
|
if (!updateFile(fileName, replacements))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2220,64 +2174,6 @@ QString findInPath(const QString &fileName)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool buildAntProject(const Options &options)
|
|
||||||
{
|
|
||||||
if (options.verbose)
|
|
||||||
fprintf(stdout, "Building Android package using ant.\n");
|
|
||||||
|
|
||||||
QString antTool = options.antTool;
|
|
||||||
if (antTool.isEmpty()) {
|
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
antTool = findInPath(QLatin1String("ant.bat"));
|
|
||||||
#else
|
|
||||||
antTool = findInPath(QLatin1String("ant"));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (antTool.isEmpty()) {
|
|
||||||
fprintf(stderr, "Cannot find ant in PATH. Please use --ant option to pass in the correct path.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.verbose)
|
|
||||||
fprintf(stdout, "Using ant: %s\n", qPrintable(antTool));
|
|
||||||
|
|
||||||
QString oldPath = QDir::currentPath();
|
|
||||||
if (!QDir::setCurrent(options.outputDirectory)) {
|
|
||||||
fprintf(stderr, "Cannot current path to %s\n", qPrintable(options.outputDirectory));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ant = QString::fromLatin1("%1 %2").arg(shellQuote(antTool)).arg(options.releasePackage ? QLatin1String(" release") : QLatin1String(" debug"));
|
|
||||||
|
|
||||||
FILE *antCommand = openProcess(ant);
|
|
||||||
if (antCommand == 0) {
|
|
||||||
fprintf(stderr, "Cannot run ant command: %s\n.", qPrintable(ant));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[512];
|
|
||||||
while (fgets(buffer, sizeof(buffer), antCommand) != 0) {
|
|
||||||
fprintf(stdout, "%s", buffer);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
int errorCode = pclose(antCommand);
|
|
||||||
if (errorCode != 0) {
|
|
||||||
fprintf(stderr, "Building the android package failed!\n");
|
|
||||||
if (!options.verbose)
|
|
||||||
fprintf(stderr, " -- For more information, run this command with --verbose.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!QDir::setCurrent(oldPath)) {
|
|
||||||
fprintf(stderr, "Cannot change back to old path: %s\n", qPrintable(oldPath));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef QMap<QByteArray, QByteArray> GradleProperties;
|
typedef QMap<QByteArray, QByteArray> GradleProperties;
|
||||||
|
|
||||||
static GradleProperties readGradleProperties(const QString &path)
|
static GradleProperties readGradleProperties(const QString &path)
|
||||||
@ -2335,7 +2231,7 @@ static bool mergeGradleProperties(const QString &path, GradleProperties properti
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool buildGradleProject(const Options &options)
|
bool buildAndroidProject(const Options &options)
|
||||||
{
|
{
|
||||||
GradleProperties localProperties;
|
GradleProperties localProperties;
|
||||||
localProperties["sdk.dir"] = options.sdkPath.toLocal8Bit();
|
localProperties["sdk.dir"] = options.sdkPath.toLocal8Bit();
|
||||||
@ -2403,12 +2299,6 @@ bool buildGradleProject(const Options &options)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool buildAndroidProject(const Options &options)
|
|
||||||
{
|
|
||||||
return options.gradle ? buildGradleProject(options)
|
|
||||||
: buildAntProject(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool uninstallApk(const Options &options)
|
bool uninstallApk(const Options &options)
|
||||||
{
|
{
|
||||||
if (options.verbose)
|
if (options.verbose)
|
||||||
@ -2445,15 +2335,11 @@ enum PackageType {
|
|||||||
QString apkPath(const Options &options, PackageType pt)
|
QString apkPath(const Options &options, PackageType pt)
|
||||||
{
|
{
|
||||||
QString path(options.outputDirectory);
|
QString path(options.outputDirectory);
|
||||||
if (options.gradle) {
|
|
||||||
path += QLatin1String("/build/outputs/apk/");
|
path += QLatin1String("/build/outputs/apk/");
|
||||||
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('-');
|
||||||
} else {
|
|
||||||
path += QLatin1String("/bin/QtApp-");
|
|
||||||
}
|
|
||||||
if (options.releasePackage) {
|
if (options.releasePackage) {
|
||||||
path += QLatin1String("release-");
|
path += QLatin1String("release-");
|
||||||
if (pt == UnsignedAPK)
|
if (pt == UnsignedAPK)
|
||||||
@ -2930,7 +2816,6 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.build) {
|
if (options.build) {
|
||||||
if (options.gradle)
|
|
||||||
cleanAndroidFiles(options);
|
cleanAndroidFiles(options);
|
||||||
if (Q_UNLIKELY(options.timing))
|
if (Q_UNLIKELY(options.timing))
|
||||||
fprintf(stdout, "[TIMING] %d ms: Cleaned Android file\n", options.timer.elapsed());
|
fprintf(stdout, "[TIMING] %d ms: Cleaned Android file\n", options.timer.elapsed());
|
||||||
@ -3005,9 +2890,6 @@ int main(int argc, char *argv[])
|
|||||||
if (Q_UNLIKELY(options.timing))
|
if (Q_UNLIKELY(options.timing))
|
||||||
fprintf(stdout, "[TIMING] %d ms: Updated files\n", options.timer.elapsed());
|
fprintf(stdout, "[TIMING] %d ms: Updated files\n", options.timer.elapsed());
|
||||||
|
|
||||||
if (!options.gradle && !createAndroidProject(options))
|
|
||||||
return CannotCreateAndroidProject;
|
|
||||||
|
|
||||||
if (Q_UNLIKELY(options.timing))
|
if (Q_UNLIKELY(options.timing))
|
||||||
fprintf(stdout, "[TIMING] %d ms: Created project\n", options.timer.elapsed());
|
fprintf(stdout, "[TIMING] %d ms: Created project\n", options.timer.elapsed());
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
// Run androiddeployqt
|
// Run androiddeployqt
|
||||||
static auto verbose = g_options.verbose ? QStringLiteral("--verbose") : QStringLiteral();
|
static auto verbose = g_options.verbose ? QStringLiteral("--verbose") : QStringLiteral();
|
||||||
if (!execCommand(QStringLiteral("%1 %3 --gradle --reinstall --output %2").arg(g_options.androidDeployQtCommand,
|
if (!execCommand(QStringLiteral("%1 %3 --reinstall --output %2").arg(g_options.androidDeployQtCommand,
|
||||||
g_options.buildPath,
|
g_options.buildPath,
|
||||||
verbose), nullptr, g_options.verbose)) {
|
verbose), nullptr, g_options.verbose)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user