Skip to content

Commit 5221f7d

Browse files
committed
Android: keep the platform minor revision for the compile SDK
Google ships no plain android-37 platform, only android-37.0 and later. Gradle resolves a bare API level to the base revision only, so dropping the minor picks the wrong platform, or none at all when just android-37.1 is installed. Write the selected platform verbatim, detect the latest one by its real directory name, and reduce it to the API level only for build.gradle files that convert it to an integer. Pick-to: 6.12 6.11 6.8 Fixes: QTBUG-149770 Change-Id: Idf487ba2522928dd200ccb9c43b082d17abdb56f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
1 parent 3d40e7f commit 5221f7d

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/tools/androiddeployqt/main.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,15 @@ Optional arguments:
707707
// gives the natural order.
708708
bool quasiLexicographicalReverseLessThan(const QFileInfo &fi1, const QFileInfo &fi2)
709709
{
710+
// baseName() drops the minor, so sort by API level, then by minor.
710711
QString s1 = fi1.baseName();
711712
QString s2 = fi2.baseName();
712713

713-
if (s1.size() == s2.size())
714-
return s1 > s2;
715-
else
714+
if (s1.size() != s2.size())
716715
return s1.size() > s2.size();
716+
if (s1 != s2)
717+
return s1 > s2;
718+
return fi1.fileName() > fi2.fileName();
717719
}
718720

719721
// Files which contain templates that need to be overwritten by build data should be overwritten every
@@ -913,8 +915,11 @@ QString detectLatestAndroidPlatform(const QString &sdkPath)
913915

914916
std::sort(fileInfos.begin(), fileInfos.end(), quasiLexicographicalReverseLessThan);
915917

918+
// Prefer the plain name any AGP understands, else the minor revision.
916919
const QFileInfo& latestPlatform = fileInfos.constFirst();
917-
return latestPlatform.baseName();
920+
if (dir.exists(latestPlatform.baseName()))
921+
return latestPlatform.baseName();
922+
return latestPlatform.fileName();
918923
}
919924

920925
QString extractPackageName(Options *options)
@@ -3116,7 +3121,16 @@ bool buildAndroidProject(const Options &options)
31163121
// Provide the integer version only if build.gradle explicitly converts to Integer,
31173122
// to avoid regression to existing projects that build for sdk platform of form android-xx.
31183123
if (gradleConfigs.usesIntegerCompileSdkVersion) {
3119-
const QByteArray tmp = options.androidPlatform.split(u'-').last().toLocal8Bit();
3124+
// An integer holds no minor, and Gradle resolves it to android-xx.0.
3125+
const QStringList platformParts = options.androidPlatform.split(u'-').last().split(u'.');
3126+
const QString apiLevel = platformParts.constFirst();
3127+
if (platformParts.size() > 1 && platformParts.at(1) != "0"_L1) {
3128+
fprintf(stderr,
3129+
"Warning: build.gradle takes an integer compile SDK version, "
3130+
"building against API level %s instead of platform %s.\n",
3131+
qPrintable(apiLevel), qPrintable(options.androidPlatform));
3132+
}
3133+
const QByteArray tmp = apiLevel.toLocal8Bit();
31203134
bool ok;
31213135
tmp.toInt(&ok);
31223136
if (ok) {

0 commit comments

Comments
 (0)