Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] don't set /uses-sdk@android:targetSdkVersion=34 by default #8138

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> ();
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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -201,18 +199,22 @@ public void SetDefaultTargetDevice ()

public virtual string ProcessManifestTemplate ()
{
var uses_sdk = new StringBuilder ("<uses-sdk ");
var uses_sdk = new StringBuilder ();
if (!string.IsNullOrEmpty (MinSdkVersion)) {
uses_sdk.Append ("<uses-sdk ");
uses_sdk.Append ("android:minSdkVersion=\"");
uses_sdk.Append (MinSdkVersion);
uses_sdk.Append ("\" ");
}
if (!string.IsNullOrEmpty (TargetSdkVersion)) {
if (uses_sdk.Length == 0)
uses_sdk.Append ("<uses-sdk ");
uses_sdk.Append ("android:targetSdkVersion=\"");
uses_sdk.Append (TargetSdkVersion);
uses_sdk.Append ("\" ");
}
uses_sdk.Append ("/>");
if (uses_sdk.Length > 0)
uses_sdk.Append ("/>");

return AndroidManifest
.Replace ("${PROJECT_NAME}", ProjectName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down