From ae68eaf0c55a2df1f9cd05a716955cca4c6c8342 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 20 Jun 2023 15:09:16 -0500 Subject: [PATCH 1/3] [tests] don't set `/uses-sdk@android:targetSdkVersion=34` by default Context: https://github.com/xamarin/xamarin-android/pull/8116/commits/95f4b796700b2acaedb9bb58ba24f84b39de8891 When making API 34 the default in .NET 8, some tests tried to build `net7.0-android` projects with an `AndroidManifest.xml` that contains: This won't work until we backport API 34 to .NET 7. In general, you shouldn't use `` in .NET 6+ apps as the following MSBuild properties should be used instead: net7.0-android33 21 Where `33` is implicit if left out. Let's no longer set `TargetSdkVersion` by default in our MSBuild tests, as this is closer to what customers will do. We also no longer build or test Xamarin.Android in main. I removed places in tests that set `TargetSdkVersion = null` and removed one test that is no longer valid in main/.NET 6+. --- .../Xamarin.Android.Build.Tests/BuildTest.cs | 22 ------------------- .../XamarinAndroidApplicationProject.cs | 4 +--- .../Tests/InstallAndRunTests.cs | 1 - 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index d87c9421df4..952c5c9d374 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -650,28 +650,6 @@ public void AarContentExtraction ([Values (false, true)] bool useAapt2) } } - [Test] - [Category ("DotNetIgnore")] // n/a in .NET 5+ - public void CheckTargetFrameworkVersion ([Values (true, false)] bool isRelease) - { - var proj = new XamarinAndroidApplicationProject () { - IsRelease = isRelease, - TargetSdkVersion = null, - MinSdkVersion = null, - }; - proj.SetProperty ("AndroidUseLatestPlatformSdk", "False"); - using (var builder = CreateApkBuilder ()) { - builder.GetTargetFrameworkVersionRange (out var _, out string firstFrameworkVersion, out var _, out string lastFrameworkVersion, out string[] _); - proj.SetProperty ("TargetFrameworkVersion", firstFrameworkVersion); - if (!Directory.Exists (Path.Combine (TestEnvironment.MonoAndroidFrameworkDirectory, firstFrameworkVersion))) - Assert.Ignore ("This is a Pull Request Build. Ignoring test."); - Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, $"Output Property: TargetFrameworkVersion={firstFrameworkVersion}"), $"TargetFrameworkVerson should be {firstFrameworkVersion}"); - Assert.IsTrue (builder.Build (proj, parameters: new [] { $"TargetFrameworkVersion={lastFrameworkVersion}" }), "Build should have succeeded."); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, $"Output Property: TargetFrameworkVersion={lastFrameworkVersion}"), $"TargetFrameworkVersion should be {lastFrameworkVersion}"); - } - } - #pragma warning disable 414 public static object [] GeneratorValidateEventNameArgs = new object [] { new object [] { false, true, string.Empty, string.Empty }, diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs index 63ecc5231f1..8b2f757897b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs @@ -70,9 +70,7 @@ public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug" MinSdkVersion = "19"; } AndroidManifest = default_android_manifest; - if (Builder.UseDotNet) { - TargetSdkVersion = XABuildConfig.AndroidDefaultTargetDotnetApiLevel.ToString (); - } else { + if (!Builder.UseDotNet) { TargetSdkVersion = AndroidSdkResolver.GetMaxInstalledPlatform ().ToString (); } LayoutMain = default_layout_main; diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 3a5875955bb..e1e874e9d72 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -80,7 +80,6 @@ public void GlobalLayoutEvent_ShouldRegisterAndFire_OnActivityLaunch ([Values (f proj = new XamarinAndroidApplicationProject () { IsRelease = isRelease, SupportedOSPlatformVersion = "23", - TargetSdkVersion = null, }; if (isRelease || !CommercialBuildAvailable) { proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64"); From 609c7bf306411092e6351485b3680a0151a67500 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 20 Jun 2023 16:50:54 -0500 Subject: [PATCH 2/3] Update XamarinAndroidApplicationProject.cs --- .../Android/XamarinAndroidApplicationProject.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs index 8b2f757897b..0a2f0e8bba3 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs @@ -199,18 +199,22 @@ public void SetDefaultTargetDevice () public virtual string ProcessManifestTemplate () { - var uses_sdk = new StringBuilder (""); + if (uses_sdk.Length > 0) + uses_sdk.Append ("/>"); return AndroidManifest .Replace ("${PROJECT_NAME}", ProjectName) From 87079c1a0958339dea7fefc528bea54e00519503 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 21 Jun 2023 09:22:35 -0500 Subject: [PATCH 3/3] Update DesignTimeBuildHasAndroidDefines --- .../Tests/Xamarin.Android.Build.Tests/BuildTest2.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs index 1569d1bdcb0..33700618d72 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs @@ -693,10 +693,8 @@ module Xamarin.Android.Tests public void DesignTimeBuildHasAndroidDefines () { var proj = new XamarinAndroidApplicationProject (); - var didParse = int.TryParse (proj.TargetSdkVersion, out int apiLevel); - Assert.IsTrue (didParse, $"Unable to parse {proj.TargetSdkVersion} as an int."); var androidDefines = new List (); - for (int i = 1; i <= apiLevel; ++i) { + for (int i = 1; i <= XABuildConfig.AndroidDefaultTargetDotnetApiLevel; ++i) { androidDefines.Add ($"!__ANDROID_{i}__"); } proj.Sources.Add (new BuildItem ("Compile", "IsAndroidDefined.cs") {