Skip to content

Commit d84a7b0

Browse files
committed
[build] Use API-21 for all native builds
Up until this commit, we have been building the 64-bit targets (`x86-64` and `armv8-a` against NDK API 21 while the 32-bit targets (`x86` and `armv7-a`) against NDK API 16. This commit changes it so that all targets build against API 21. This gives us the ability to speed up Debug builds on 32-bit platforms via use of POSIX APIs for directory traversal that are available starting from API 21 onwards (`openat` and `fstatat`). The switch to API 21 was initially planned for .NET5 but there's no harm in making the change now. In addition, this commit updates versions of several components: * Bump emulator version to 30.0.5 * Bump NDK version to 21b (21.1.6352462) * Bump x86 system image revision to 7 Also, `XABuildConfig.NDKMinimumApiAvailable` is now set to the minimum supported NDK API level instead of the minimum API level *installed* by the NDK.
1 parent a9bbb62 commit d84a7b0

File tree

9 files changed

+43
-19
lines changed

9 files changed

+43
-19
lines changed

Configuration.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' And '$(UsingMicrosoftNETSdk)' != 'true' ">v4.7.1</TargetFrameworkVersion>
2020
<!-- Used by the `build-tools/create-vsix` build so that `Mono.Android.Export.dll`/etc. are only included *once* -->
2121
<!-- Should correspond to the first value from `$(API_LEVELS)` in `build-tools/api-xml-adjuster/Makefile` -->
22-
<AndroidFirstFrameworkVersion Condition="'$(AndroidFirstFrameworkVersion)' == ''">v4.4</AndroidFirstFrameworkVersion>
23-
<AndroidFirstApiLevel Condition="'$(AndroidFirstApiLevel)' == ''">19</AndroidFirstApiLevel>
22+
<AndroidFirstFrameworkVersion Condition="'$(AndroidFirstFrameworkVersion)' == ''">v5.0</AndroidFirstFrameworkVersion>
23+
<AndroidFirstApiLevel Condition="'$(AndroidFirstApiLevel)' == ''">21</AndroidFirstApiLevel>
2424
<AndroidFirstPlatformId Condition="'$(AndroidFirstPlatformId)' == ''">$(AndroidFirstApiLevel)</AndroidFirstPlatformId>
2525
<_IsRunningNuGetRestore Condition="$(RestoreTaskAssemblyFile.EndsWith('NuGet.exe', StringComparison.InvariantCultureIgnoreCase))">True</_IsRunningNuGetRestore>
2626
<!-- *Latest* *stable* API level binding that we support; used when building src/Xamarin.Android.Build.Tasks -->
@@ -136,8 +136,8 @@
136136
<AndroidToolPath Condition=" '$(AndroidToolPath)' == '' ">$(AndroidSdkFullPath)\tools</AndroidToolPath>
137137
<AndroidToolsBinPath Condition=" '$(AndroidToolsBinPath)' == '' ">$(AndroidToolPath)\bin</AndroidToolsBinPath>
138138
<AndroidToolExe Condition=" '$(AndroidToolExe)' == '' ">android</AndroidToolExe>
139-
<EmulatorVersion Condition=" '$(EmulatorVersion)' == '' ">5598178</EmulatorVersion>
140-
<EmulatorPkgRevision Condition=" '$(EmulatorPkgRevision)' == '' ">29.0.11</EmulatorPkgRevision>
139+
<EmulatorVersion Condition=" '$(EmulatorVersion)' == '' ">6306047</EmulatorVersion>
140+
<EmulatorPkgRevision Condition=" '$(EmulatorPkgRevision)' == '' ">30.0.5</EmulatorPkgRevision>
141141
<EmulatorToolPath Condition=" '$(EmulatorToolPath)' == '' ">$(AndroidSdkFullPath)\emulator</EmulatorToolPath>
142142
<EmulatorToolExe Condition=" '$(EmulatorToolExe)' == '' ">emulator</EmulatorToolExe>
143143
<NdkBuildPath Condition=" '$(NdkBuildPath)' == '' And '$(HostOS)' != 'Windows' ">$(AndroidNdkDirectory)\ndk-build</NdkBuildPath>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### Minimum compatible Android version now Android 5.0 Lollipop (API level 21)
2+
3+
The minimum compatible Android version for Xamarin.Android apps is now Android
4+
5.0 Lollipop (API level 21). Warning XA4216 has been updated to help highlight
5+
this change for any projects that might still have an older version set for the
6+
`minSdkVersion` in the `AndroidManifest.xml` file:
7+
8+
```
9+
warning XA4216: AndroidManifest.xml //uses-sdk/@android:minSdkVersion '20' is less than API-21, this configuration is not supported.
10+
```
11+
12+
#### Background information
13+
14+
The unmanaged native libraries that are part of Xamarin.Android are now built to
15+
target Android 5.0 Lollipop (API level 21), so apps built using this release can
16+
abort due to incompatible APIs if run on earlier Android versions.

build-tools/api-merge/merge-configuration.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
<File Path="api-R.xml.in" Level="R" />
2222
</Inputs>
2323
<Outputs>
24-
<File Path="android-19\mcw\api.xml" LastLevel="19" />
25-
<File Path="android-20\mcw\api.xml" LastLevel="20" />
2624
<File Path="android-21\mcw\api.xml" LastLevel="21" />
2725
<File Path="android-22\mcw\api.xml" LastLevel="22" />
2826
<File Path="android-23\mcw\api.xml" LastLevel="23" />

build-tools/api-xml-adjuster/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ API_XML_TOOL = $(BUILDBIN)/api-xml-adjuster.exe
1717
RUNTIME = mono --debug
1818
RUN_CLASS_PARSE = $(RUNTIME) $(CLASS_PARSE)
1919
RUN_API_XML_TOOL = $(RUNTIME) $(API_XML_TOOL)
20-
API_LEVELS = 10 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 R
20+
API_LEVELS = 21 22 23 24 25 26 27 28 29 R
2121

2222
XML_OUTPUT_DIR = .
2323

build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace Xamarin.Android.Prepare
55
{
66
class BuildAndroidPlatforms
77
{
8-
public const string AndroidNdkVersion = "21";
9-
public const string AndroidNdkPkgRevision = "21.0.6113669";
8+
public const string AndroidNdkVersion = "21b";
9+
public const string AndroidNdkPkgRevision = "21.1.6352462";
1010

1111
public static readonly List<AndroidPlatform> AllPlatforms = new List<AndroidPlatform> {
1212
new AndroidPlatform (apiName: "", apiLevel: 1, platformID: "1"),
@@ -27,8 +27,8 @@ class BuildAndroidPlatforms
2727
new AndroidPlatform (apiName: "Jelly Bean", apiLevel: 16, platformID: "16", include: "v4.1"),
2828
new AndroidPlatform (apiName: "Jelly Bean", apiLevel: 17, platformID: "17", include: "v4.2"),
2929
new AndroidPlatform (apiName: "Jelly Bean", apiLevel: 18, platformID: "18", include: "v4.3"),
30-
new AndroidPlatform (apiName: "Kit Kat", apiLevel: 19, platformID: "19", include: "v4.4", framework: "v4.4"),
31-
new AndroidPlatform (apiName: "Kit Kat + Wear support", apiLevel: 20, platformID: "20", include: "v4.4.87", framework: "v4.4.87"),
30+
new AndroidPlatform (apiName: "Kit Kat", apiLevel: 19, platformID: "19", include: "v4.4"),
31+
new AndroidPlatform (apiName: "Kit Kat + Wear support", apiLevel: 20, platformID: "20", include: "v4.4.87"),
3232
new AndroidPlatform (apiName: "Lollipop", apiLevel: 21, platformID: "21", include: "v5.0", framework: "v5.0"),
3333
new AndroidPlatform (apiName: "Lollipop", apiLevel: 22, platformID: "22", include: "v5.1", framework: "v5.1"),
3434
new AndroidPlatform (apiName: "Marshmallow", apiLevel: 23, platformID: "23", include: "v6.0", framework: "v6.0"),
@@ -42,9 +42,9 @@ class BuildAndroidPlatforms
4242
};
4343

4444
public static readonly Dictionary<string, uint> NdkMinimumAPI = new Dictionary<string, uint> {
45-
{ AbiNames.TargetJit.AndroidArmV7a, 16 },
45+
{ AbiNames.TargetJit.AndroidArmV7a, 21 },
4646
{ AbiNames.TargetJit.AndroidArmV8a, 21 },
47-
{ AbiNames.TargetJit.AndroidX86, 16 },
47+
{ AbiNames.TargetJit.AndroidX86, 21 },
4848
{ AbiNames.TargetJit.AndroidX86_64, 21 },
4949
};
5050
}

build-tools/xaprepare/xaprepare/ConfigAndData/Dependencies/AndroidToolchain.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public AndroidToolchain ()
4444

4545
new AndroidToolchainComponent ("docs-24_r01", destDir: "docs", pkgRevision: "1"),
4646
new AndroidToolchainComponent ("android_m2repository_r47", destDir: Path.Combine ("extras", "android", "m2repository"), pkgRevision: "47.0.0"),
47-
new AndroidToolchainComponent ("x86-29_r06", destDir: Path.Combine ("system-images", "android-29", "default", "x86"), relativeUrl: new Uri ("sys-img/android/", UriKind.Relative), pkgRevision: "6"),
47+
48+
// NOTE: for some reason x86-29_r07 zips are tagged with the OS name, JUST this system image - when
49+
// updating to a latter version check if that's changed or not.
50+
new AndroidToolchainComponent ($"x86-29_r07-{osTag}", destDir: Path.Combine ("system-images", "android-29", "default", "x86"), relativeUrl: new Uri ("sys-img/android/", UriKind.Relative), pkgRevision: "7"),
4851
new AndroidToolchainComponent ($"android-ndk-r{AndroidNdkVersion}-{osTag}-x86_64", destDir: AndroidNdkDirectory, pkgRevision: AndroidPkgRevision),
4952
new AndroidToolchainComponent ($"build-tools_r{XABuildToolsVersion}-{altOsTag}", destDir: Path.Combine ("build-tools", XABuildToolsFolder), isMultiVersion: true),
5053
new AndroidToolchainComponent ($"platform-tools_r{XAPlatformToolsVersion}-{osTag}", destDir: "platform-tools", pkgRevision: XAPlatformToolsVersion),

build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,17 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
114114
{
115115
const string OutputFileName = "XABuildConfig.cs";
116116

117+
uint minimumApiAvailable = UInt32.MaxValue;
118+
foreach (uint api in BuildAndroidPlatforms.NdkMinimumAPI.Values) {
119+
if (api > minimumApiAvailable)
120+
continue;
121+
minimumApiAvailable = api;
122+
}
123+
117124
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
118125
{ "@NDK_REVISION@", context.BuildInfo.NDKRevision },
119126
{ "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion },
120-
{ "@NDK_MINIMUM_API_AVAILABLE@", context.BuildInfo.NDKMinimumApiAvailable },
127+
{ "@NDK_MINIMUM_API_AVAILABLE@", minimumApiAvailable.ToString () },
121128
{ "@NDK_VERSION_MAJOR@", context.BuildInfo.NDKVersionMajor },
122129
{ "@NDK_VERSION_MINOR@", context.BuildInfo.NDKVersionMinor },
123130
{ "@NDK_VERSION_MICRO@", context.BuildInfo.NDKVersionMicro },

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void TestNdkUtil ()
4141
Assert.IsTrue (NdkUtil.ValidateNdkPlatform (log, ndkDir, arch, enableLLVM: false));
4242
Assert.AreEqual (0, errors.Count, "NdkUtil.ValidateNdkPlatform should not have returned false.");
4343
int level = NdkUtil.GetMinimumApiLevelFor (arch, ndkDir);
44-
int expected = 16;
44+
int expected = 21;
4545
Assert.AreEqual (expected, level, $"Min Api Level for {arch} should be {expected}.");
4646
var compilerNoQuotes = NdkUtil.GetNdkTool (ndkDir, arch, "gcc", level);
4747
Assert.AreEqual (0, errors.Count, "NdkUtil.GetNdkTool should not have errored.");

src/monodroid/jni/embedded-assemblies.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ EmbeddedAssemblies::typemap_read_header ([[maybe_unused]] int dir_fd, const char
583583
struct stat sbuf;
584584
int res;
585585

586-
#if __ANDROID_API__ < 21
586+
#if defined (WINDOWS)
587587
simple_pointer_guard<char[]> full_file_path = utils.path_combine (dir_path, file_path);
588588
res = stat (full_file_path, &sbuf);
589589
#else
@@ -600,7 +600,7 @@ EmbeddedAssemblies::typemap_read_header ([[maybe_unused]] int dir_fd, const char
600600
return false;
601601
}
602602

603-
#if __ANDROID_API__ < 21
603+
#if defined (WINDOWS)
604604
fd = open (full_file_path, O_RDONLY);
605605
#else
606606
fd = openat (dir_fd, file_path, O_RDONLY);
@@ -800,7 +800,7 @@ EmbeddedAssemblies::try_load_typemaps_from_directory (const char *path)
800800
}
801801

802802
int dir_fd;
803-
#if __ANDROID_API__ < 21
803+
#if WINDOWS
804804
dir_fd = -1;
805805
#else
806806
dir_fd = dirfd (dir);

0 commit comments

Comments
 (0)