[go: nahoru, domu]

Skip to content

Commit

Permalink
[Mono.Android] API-31 stabilization (dotnet#6174)
Browse files Browse the repository at this point in the history
Context: https://developer.android.com/about/versions/12

API-31 has been enumified (8843808, cf2a39b, cf2a39b).
Time to declare it stable!

Set API-S as API-31, `$(TargetFrameworkVersion)`=v12.0,
`$(AndroidPackVersion)`=31.0.100, and declare as stable.

Update unit test files so `$(TargetFrameworkVersion)`= v12.0 (API-31)
*or* `$(TargetFrameworkVersion)` isn't needed, a'la 8140991.

Rename `src/Mono.Android/Profiles/api-S.params.txt` to
`api-31.params.txt`, to match the stable API-level ID.

Updated `tests/api-compatibility/acceptable-breakages-vReference.txt`
because the default API compare will now be against `API-31`, not
`API-30`, and we deliberately removed the `[Category]` custom attribute
(e5a4bee), remove `[DataContractAttribute]` (101fea2), and fix the
value of `Android.OS.BuildVersionCodes.R` (1b1ec09).

Support `$(AndroidUseLatestPlatformSdk)` in binding projects: once
API-31 is stable, binding projects with
`$(TargetFrameworkVersion)`=v11.0 and
`$(AndroidUseLatestPlatformSdk)`=true fail to build with:

	Task ResolveNuGetPackageAssets
	...
	Microsoft.NuGet.targets(198,5): Your project does not reference "MonoAndroid,Version=v12.0" framework. Add a reference to "MonoAndroid,Version=v12.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.

What happened is that `$(TargetFrameworkVersion)` was changed to 12.0
during `Build`, but not during `Restore`. Thus NuGet restored with
`MonoAndroid,Version=v11.0` instead of `MonoAndroid,Version=v12.0`.

I found that we have this setup for other project types, but not
binding projects:

	<!--
	  NOTE:
	  This target runs during Restore, and there is no $(RestoreDependsOn) property.
	  There appears to be no other way to do this other than use BeforeTargets.
	-->
	<Target Name="_SetLatestTargetFrameworkVersionForPackageReference"
	    Condition=" '$(AndroidUseLatestPlatformSdk)' == 'True' "
	    BeforeTargets="_GetRestoreTargetFrameworksOutput"
	    DependsOnTargets="_SetLatestTargetFrameworkVersion">
	</Target>

If we move this target to `Xamarin.Android.Legacy.targets`, it will be
imported by binding projects.

We also get the added benefit of it not being in .NET 6.
`$(AndroidUseLatestPlatformSdk)` is not supported in .NET 6, so we
should not have this MSBuild target there.

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
  • Loading branch information
jpobst and jonathanpeppers committed Aug 23, 2021
1 parent 7a65959 commit e722825
Show file tree
Hide file tree
Showing 27 changed files with 106 additions and 127 deletions.
6 changes: 3 additions & 3 deletions Configuration.Override.props.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
kept consistent with each other, lest Bad Things Happen™
-->
<!-- The default Android API level to bind in src/Mono.Android -->
<AndroidApiLevel>30</AndroidApiLevel>
<AndroidApiLevel>31</AndroidApiLevel>
<!-- The Xamarin.Android $(TargetFrameworkVersion) value that corresponds to $(AndroidApiLevel) -->
<AndroidFrameworkVersion>v11.0</AndroidFrameworkVersion>
<AndroidFrameworkVersion>v12.0</AndroidFrameworkVersion>
<!-- The default Android API "id" that corresponds to $(AndroidApiLevel) -->
<AndroidPlatformId>30</AndroidPlatformId>
<AndroidPlatformId>31</AndroidPlatformId>

<!--
Colon-separated list of ABIs to build the mono JIT for.
Expand Down
4 changes: 2 additions & 2 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
<AndroidFirstPlatformId Condition="'$(AndroidFirstPlatformId)' == ''">$(AndroidFirstApiLevel)</AndroidFirstPlatformId>
<_IsRunningNuGetRestore Condition="$(RestoreTaskAssemblyFile.EndsWith('NuGet.exe', StringComparison.InvariantCultureIgnoreCase))">True</_IsRunningNuGetRestore>
<!-- *Latest* *stable* API level binding that we support; used when building src/Xamarin.Android.Build.Tasks -->
<AndroidLatestStableApiLevel Condition="'$(AndroidLatestStableApiLevel)' == ''">30</AndroidLatestStableApiLevel>
<AndroidLatestStableApiLevel Condition="'$(AndroidLatestStableApiLevel)' == ''">31</AndroidLatestStableApiLevel>
<AndroidLatestStablePlatformId Condition="'$(AndroidLatestStablePlatformId)' == ''">$(AndroidLatestStableApiLevel)</AndroidLatestStablePlatformId>
<AndroidLatestStableFrameworkVersion Condition="'$(AndroidLatestStableFrameworkVersion)'==''">v11.0</AndroidLatestStableFrameworkVersion>
<AndroidLatestStableFrameworkVersion Condition="'$(AndroidLatestStableFrameworkVersion)'==''">v12.0</AndroidLatestStableFrameworkVersion>
<!-- The API level and TargetFrameworkVersion for the default Mono.Android.dll build -->
<AndroidApiLevel Condition=" '$(AndroidApiLevel)' == '' ">$(AndroidLatestStableApiLevel)</AndroidApiLevel>
<AndroidPlatformId Condition=" '$(AndroidPlatformId)' == '' ">$(AndroidLatestStablePlatformId)</AndroidPlatformId>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Bump last two digits of the patch version for service releases.
* Bump first digit of the patch version for feature releases (and reset the first two digits to 0)
-->
<AndroidPackVersion>30.0.100</AndroidPackVersion>
<AndroidPackVersion>31.0.100</AndroidPackVersion>
<AndroidPackVersionSuffix>rc.2</AndroidPackVersionSuffix>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Documentation/building/windows/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ After the solution has built successfully, you can [use your
build][using-your-build] to build Xamarin.Android application and library
projects. Note that by default `Xamarin.Android.sln` only builds support for
the `$(TargetFrameworkVersion)` specified in the `$(AndroidFrameworkVersion)`
property of the [`Configuration.props`][configprops-main] file (`v11.0` when
property of the [`Configuration.props`][configprops-main] file (`v12.0` when
this guide was last updated), so you will need to ensure that your application
and library projects are configured to use that particular target framework
version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class CheckApiCompatibility : Task
{ "v9.0", "v8.1" },
{ "v10.0", "v9.0" },
{ "v11.0", "v10.0" },
{ "v11.0.99", "v11.0" },
{ "v12.0", "v11.0" },
};

static readonly string assemblyToValidate = "Mono.Android.dll";
Expand Down
4 changes: 2 additions & 2 deletions build-tools/api-merge/merge-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<File Path="api-28.xml.in" Level="28" />
<File Path="api-29.xml.in" Level="29" />
<File Path="api-30.xml.in" Level="30" />
<File Path="api-S.xml.in" Level="S" />
<File Path="api-31.xml.in" Level="31" />
</Inputs>
<Outputs>
<File Path="android-19\mcw\api.xml" LastLevel="19" />
Expand All @@ -34,6 +34,6 @@
<File Path="android-28\mcw\api.xml" LastLevel="28" />
<File Path="android-29\mcw\api.xml" LastLevel="29" />
<File Path="android-30\mcw\api.xml" LastLevel="30" />
<File Path="android-S\mcw\api.xml" LastLevel="S" />
<File Path="android-31\mcw\api.xml" LastLevel="31" />
</Outputs>
</Configuration>
2 changes: 1 addition & 1 deletion build-tools/api-xml-adjuster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ API_XML_TOOL = $(BUILDBIN)/api-xml-adjuster.exe
RUNTIME = mono --debug
RUN_CLASS_PARSE = $(RUNTIME) $(CLASS_PARSE)
RUN_API_XML_TOOL = $(RUNTIME) $(API_XML_TOOL)
API_LEVELS = 10 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 S
API_LEVELS = 10 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

XML_OUTPUT_DIR = .

Expand Down
6 changes: 0 additions & 6 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,6 @@ stages:
job_name: mac_msbuild_tests_1
job_suffix: Legacy
nunit_categories: '&& cat != SmokeTests'
jdkTestFolder: $(XA.Jdk8.Folder)

- template: yaml-templates\run-msbuild-mac-tests.yaml
parameters:
Expand All @@ -941,15 +940,13 @@ stages:
job_suffix: Legacy
nunit_categories: '&& cat != SmokeTests'
run_extra_tests: true
jdkTestFolder: $(XA.Jdk8.Folder)

- template: yaml-templates\run-msbuild-mac-tests.yaml
parameters:
node_id: 3
job_name: mac_msbuild_tests_3
job_suffix: Legacy
nunit_categories: '&& cat != SmokeTests'
jdkTestFolder: $(XA.Jdk8.Folder)

# Xamarin.Android (Test MSBuild Legacy - Windows)
- template: yaml-templates\run-msbuild-win-tests.yaml
Expand All @@ -958,7 +955,6 @@ stages:
job_name: win_msbuild_tests_1
job_suffix: Legacy
nunit_categories: '&& cat != SmokeTests'
jdkTestFolder: $(XA.Jdk8.Folder)

- template: yaml-templates\run-msbuild-win-tests.yaml
parameters:
Expand All @@ -967,15 +963,13 @@ stages:
job_suffix: Legacy
nunit_categories: '&& cat != SmokeTests'
run_extra_tests: true
jdkTestFolder: $(XA.Jdk8.Folder)

- template: yaml-templates\run-msbuild-win-tests.yaml
parameters:
node_id: 3
job_name: win_msbuild_tests_3
job_suffix: Legacy
nunit_categories: '&& cat != SmokeTests'
jdkTestFolder: $(XA.Jdk8.Folder)

- stage: msbuild_dotnet
displayName: One .NET Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BuildAndroidPlatforms
new AndroidPlatform (apiName: "Pie", apiLevel: 28, platformID: "28", include: "v9.0", framework: "v9.0"),
new AndroidPlatform (apiName: "Q", apiLevel: 29, platformID: "29", include: "v10.0", framework: "v10.0"),
new AndroidPlatform (apiName: "R", apiLevel: 30, platformID: "30", include: "v11.0", framework: "v11.0"),
new AndroidPlatform (apiName: "S", apiLevel: 31, platformID: "S", include: "v11.0.99", framework: "v11.0.99", stable: false),
new AndroidPlatform (apiName: "S", apiLevel: 31, platformID: "31", include: "v12.0", framework: "v12.0"),
};

// These are here until we can drop "legacy" targets and use only .NET6+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AndroidToolchain ()
new AndroidPlatformComponent ("platform-28_r04", apiLevel: "28", pkgRevision: "4"),
new AndroidPlatformComponent ("platform-29_r01", apiLevel: "29", pkgRevision: "1"),
new AndroidPlatformComponent ("platform-30_r01", apiLevel: "30", pkgRevision: "1"),
new AndroidPlatformComponent ("platform-31_r01", apiLevel: "S", pkgRevision: "1"),
new AndroidPlatformComponent ("platform-31_r01", apiLevel: "31", pkgRevision: "1"),

new AndroidToolchainComponent ("sources-30_r01", destDir: Path.Combine ("platforms", $"android-30", "src"), pkgRevision: "1", dependencyType: AndroidToolchainComponentType.BuildDependency),

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ public void RemoveEventHandlerResolution ()
{
var binding = new XamarinAndroidBindingProject () {
IsRelease = true,
UseLatestPlatformSdk = true,
Jars = {
new AndroidItem.LibraryProjectZip ("Jars\\ActionBarSherlock-4.3.1.zip") {
WebContent = "https://github.com/xamarin/monodroid-samples/blob/master/ActionBarSherlock/ActionBarSherlock/Jars/ActionBarSherlock-4.3.1.zip?raw=true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
using Xamarin.Tools.Zip;
using Microsoft.Android.Build.Tasks;

#if !NET472
namespace Xamarin.Android.Build.Tests
{
[TestFixture]
[NonParallelizable] // On MacOS, parallel /restore causes issues
[Category ("Node-2"), Category ("DotNetIgnore")] // These don't need to run under `dotnet test`
[Category ("Node-2")]
public class XASdkTests : BaseTest
{
/// <summary>
Expand Down Expand Up @@ -207,7 +208,7 @@ public void DotNetNew ([Values ("android", "androidlib", "android-bindinglib")]
}

[Test]
public void DotNetPack ([Values ("net6.0-android", "net6.0-android30")] string targetFramework)
public void DotNetPack ([Values ("net6.0-android", "net6.0-android31")] string targetFramework)
{
var proj = new XASdkProject (outputType: "Library") {
TargetFramework = targetFramework,
Expand Down Expand Up @@ -239,8 +240,8 @@ public void DotNetPack ([Values ("net6.0-android", "net6.0-android30")] string t
var nupkgPath = Path.Combine (FullProjectDirectory, proj.OutputPath, "..", $"{proj.ProjectName}.1.0.0.nupkg");
FileAssert.Exists (nupkgPath);
using (var nupkg = ZipHelper.OpenZip (nupkgPath)) {
nupkg.AssertContainsEntry (nupkgPath, $"lib/net6.0-android30.0/{proj.ProjectName}.dll");
nupkg.AssertContainsEntry (nupkgPath, $"lib/net6.0-android30.0/{proj.ProjectName}.aar");
nupkg.AssertContainsEntry (nupkgPath, $"lib/net6.0-android31.0/{proj.ProjectName}.dll");
nupkg.AssertContainsEntry (nupkgPath, $"lib/net6.0-android31.0/{proj.ProjectName}.aar");
}
}

Expand Down Expand Up @@ -456,7 +457,7 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
$"{proj.ProjectName}.runtimeconfig.json",
$"{proj.ProjectName}.xml",
};
CollectionAssert.AreEqual (expectedFiles, files, $"Expected: {string.Join (";", expectedFiles)}\n Found: {string.Join (";", files)}");
CollectionAssert.AreEquivalent (expectedFiles, files, $"Expected: {string.Join (";", expectedFiles)}\n Found: {string.Join (";", files)}");

var assemblyPath = Path.Combine (outputPath, $"{proj.ProjectName}.dll");
FileAssert.Exists (assemblyPath);
Expand All @@ -483,7 +484,7 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
XNamespace ns = "http://schemas.android.com/apk/res/android";
var uses_sdk = manifest.Root.Element ("uses-sdk");
Assert.AreEqual ("21", uses_sdk.Attribute (ns + "minSdkVersion").Value);
Assert.AreEqual ("30", uses_sdk.Attribute (ns + "targetSdkVersion").Value);
Assert.AreEqual ("31", uses_sdk.Attribute (ns + "targetSdkVersion").Value);

bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease);
var apkPath = Path.Combine (outputPath, $"{proj.PackageName}.apk");
Expand All @@ -505,6 +506,11 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot)
}
}


/// <summary>
/// NOTE: we cannot use SupportedOSPlatformVersion=31 yet, due to d8 2.2.64 emitting a warning for `--min-api 31`:
/// D8 An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier
/// </summary>
[Test]
public void SupportedOSPlatformVersion ([Values (21, 30)] int minSdkVersion)
{
Expand Down Expand Up @@ -617,7 +623,7 @@ public void XamarinLegacySdk ()
};

using var b = new Builder ();
var dotnetTargetFramework = "net6.0-android30.0";
var dotnetTargetFramework = "net6.0-android31.0";
var legacyTargetFrameworkVersion = "11.0";
var legacyTargetFramework = $"monoandroid{legacyTargetFrameworkVersion}";
proj.SetProperty ("TargetFramework", value: "");
Expand All @@ -634,7 +640,7 @@ public void XamarinLegacySdk ()
}

[Test]
public void MauiTargetFramework ([Values ("net6.0-android", "net6.0-android30", "net6.0-android30.0")] string targetFramework)
public void MauiTargetFramework ([Values ("net6.0-android", "net6.0-android31", "net6.0-android31.0")] string targetFramework)
{
var library = new XASdkProject (outputType: "Library") {
TargetFramework = targetFramework,
Expand Down Expand Up @@ -731,3 +737,4 @@ DotNetCLI CreateDotNetBuilder (XASdkProject project, string relativeProjectDir =
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Xamarin.ProjectTools
{
public static class Versions
{
public const string Android12 = "v12.0";
public const string Android11 = "v11.0";
/// <summary>
/// Previously known as Q
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Size": 57802
},
"assemblies/Mono.Android.dll": {
"Size": 82977
"Size": 83219
},
"assemblies/rc.bin": {
"Size": 946
Expand All @@ -17,22 +17,22 @@
"Size": 11292
},
"assemblies/System.Private.CoreLib.dll": {
"Size": 532778
"Size": 533257
},
"assemblies/System.Runtime.dll": {
"Size": 2676
"Size": 2681
},
"assemblies/UnnamedProject.dll": {
"Size": 3171
"Size": 3186
},
"classes.dex": {
"Size": 316792
"Size": 345240
},
"lib/arm64-v8a/libmonodroid.so": {
"Size": 338784
},
"lib/arm64-v8a/libmonosgen-2.0.so": {
"Size": 3155488
"Size": 3163680
},
"lib/arm64-v8a/libSystem.IO.Compression.Native.so": {
"Size": 776216
Expand Down Expand Up @@ -77,5 +77,5 @@
"Size": 1724
}
},
"PackageSize": 2688851
"PackageSize": 2697043
}
Loading

0 comments on commit e722825

Please sign in to comment.