-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Microsoft.Android.Sdk] use net5.0-android $(TargetFramework)
After bumping to .NET 5.0.100-rc.2.20459.1, we can now use: <TargetFramework>net5.0-android</TargetFramework> On the first try, this failed with: error NETSDK1139: The target platform identifier android was not recognized. Our SDK needs to specify: <TargetPlatformSupported Condition=" '$(TargetPlatformIdentifier)' == 'Android' ">true</TargetPlatformSupported> After doing this, everything seemed to work as before. I updated tests so they will use `net5.0-android` going forward. ~~ @(SdkSupportedTargetPlatform) ~~ A second part of this change is the need to fill out `$(TargetPlatformVersion)`, `@(AndroidSdkSupportedTargetPlatform)`, and `@(SdkSupportedTargetPlatform)` similar to: https://github.com/dotnet/sdk/blob/c43785736edc8d4bc927df3b557c1609d028cd93/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSdkSupportedTargetPlatforms.props Using this data, the dotnet/sdk will run the `GenerateTargetPlatformDefineConstants` MSBuild target: https://github.com/dotnet/sdk/blob/a0e17b2b5d2ec75c16e1083b1f926a258126c73a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets#L188-L198 This fills out `$(DefineConstants)` with `ANDROID;ANDROID21;...;ANDROID30`.
- Loading branch information
1 parent
3a067cc
commit 620c73f
Showing
13 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...d.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/GenerateSupportedPlatforms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Xamarin.Android.Tools.BootstrapTasks | ||
{ | ||
/// <summary> | ||
/// Generates Microsoft.Android.Sdk.SupportedPlatforms.props | ||
/// Similar to: https://github.com/dotnet/sdk/blob/18ee4eac8b3abe6d554d2e0c39d8952da0f23ce5/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSupportedTargetPlatforms.props | ||
/// </summary> | ||
public class GenerateSupportedPlatforms : Task | ||
{ | ||
/// <summary> | ||
/// A list of AndroidApiInfo.xml files produced by Mono.Android.targets | ||
/// </summary> | ||
[Required] | ||
public string [] AndroidApiInfo { get; set; } | ||
|
||
/// <summary> | ||
/// The output file to generate | ||
/// </summary> | ||
[Required] | ||
public string OutputFile { get; set; } | ||
|
||
/// <summary> | ||
/// $(AndroidMinimumDotNetApiLevel) from Configuration.props | ||
/// </summary> | ||
[Required] | ||
public int MinimumApiLevel { get; set; } | ||
|
||
public override bool Execute () | ||
{ | ||
if (AndroidApiInfo.Length == 0) { | ||
Log.LogError ("This task requires at least one AndroidApiInfo.xml file!"); | ||
return false; | ||
} | ||
|
||
var versions = new AndroidVersions ( | ||
AndroidApiInfo.Select (d => Path.GetDirectoryName (d))); | ||
var settings = new XmlWriterSettings { | ||
OmitXmlDeclaration = true, | ||
Indent = true, | ||
}; | ||
using (var writer = XmlWriter.Create (OutputFile, settings)) { | ||
|
||
writer.WriteComment ($@" | ||
*********************************************************************************************** | ||
{Path.GetFileName (OutputFile)} | ||
Specifies the supported Android platform versions for this SDK. | ||
*********************************************************************************************** | ||
"); | ||
writer.WriteStartElement ("Project"); | ||
|
||
writer.WriteStartElement ("PropertyGroup"); | ||
writer.WriteStartElement ("TargetPlatformVersion"); | ||
writer.WriteAttributeString ("Condition", " '$(TargetPlatformVersion)' == '' "); | ||
writer.WriteString (versions.MaxStableVersion.ApiLevel.ToString ()); | ||
writer.WriteEndElement (); // </TargetPlatformVersion> | ||
writer.WriteEndElement (); // </PropertyGroup> | ||
|
||
writer.WriteStartElement ("ItemGroup"); | ||
foreach (AndroidVersion version in versions.InstalledBindingVersions | ||
.Where (v => v.ApiLevel >= MinimumApiLevel) | ||
.OrderBy (v => v.ApiLevel)) { | ||
writer.WriteStartElement ("AndroidSdkSupportedTargetPlatform"); | ||
writer.WriteAttributeString ("Include", version.ApiLevel.ToString ()); | ||
writer.WriteEndElement (); // </AndroidSdkSupportedTargetPlatform> | ||
} | ||
writer.WriteStartElement ("SdkSupportedTargetPlatform"); | ||
writer.WriteAttributeString ("Condition", " '$(TargetPlatformIdentifier)' == 'Android' "); | ||
writer.WriteAttributeString ("Include", "@(AndroidSdkSupportedTargetPlatform)"); | ||
|
||
writer.WriteEndDocument (); // </Project> | ||
} | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.BundledVersions.props | ||
/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.SupportedPlatforms.props | ||
/Xamarin.Android.Common.props | ||
/Xamarin.Android.BuildInfo.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/CodeBehind/CommonSampleLibrary/CommonSampleLibraryDotNet.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters