-
Notifications
You must be signed in to change notification settings - Fork 564
[.NET 5] fix warning for $(TFV) of 5.0 #4598
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
Conversation
| /// <summary> | ||
| /// This is used instead of TargetFrameworkVersion for .NET 5 builds | ||
| /// </summary> | ||
| public int ApiLevel { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public int ApiLevel { get; set; } | |
| public int TargetApiLevel { get; set; } |
This is more clear in intent than the previous name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this instead be string TargetAndroidId (plus associated chicanery and conversions), so that it can “reasonably” support preview API levels, such as this year’s current R (and presumably next year’s S, and...)?
AndroidManifest.xml has historically allowed //uses-sdk/@android:targetSdkVersion to contain values such as R, and we’ve historically allowed $(TargetFrameworkVersion) to be e.g. v10.0.99 to use the preview API level, and we need some form of equivalent in .NET 5, especially since we’ll be losing $(TargetFrameworkVersion)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonp for .NET 5 the incoming value here will be $(_AndroidApiLevel), which is currently coming from:
I don't think we have a way to set this to an unstable API level yet in .NET 5, but the value would be set to 30 instead of R.
I think the name ApiLevel is OK, because we've used this for other tasks that take $(_AndroidApiLevel) as input:
A couple older tasks use the name AndroidSdkPlatform, though.
|
|
||
| var compileSdk = MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (TargetFrameworkVersion); | ||
| var compileSdk = string.IsNullOrEmpty (TargetFrameworkVersion) ? | ||
| ApiLevel : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ApiLevel : | |
| TargetApiLevel : |
| <Target Name="_CheckGoogleSdkRequirements" | ||
| Condition="Exists('$(IntermediateOutputPath)android\AndroidManifest.xml') And '$(AndroidEnableGooglePlayStoreChecks)' == 'true' "> | ||
| <CheckGoogleSdkRequirements | ||
| ApiLevel="$(_AndroidApiLevel)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ApiLevel="$(_AndroidApiLevel)" | |
| TargetApiLevel="$(_AndroidApiLevel)" |
In our current .NET 5 builds, you always hit:
warning XA1008: The TargetFrameworkVersion (Android API level 21) is lower than the targetSdkVersion (29).
Please increase the `$(TargetFrameworkVersion)` or decrease the `android:targetSdkVersion` in the `AndroidManifest.xml` so that the API levels match.
It is giving a warning for Google Play, because
`$(TargetFrameworkVersion)` is equal to 5.0.
To fix this, I modified the `<CheckGoogleSdkRequirements/>` MSBuild
task so that `TargetFrameworkVersion` is optional. For .NET 5 builds,
we can pass in `$(_AndroidApiLevel)` instead.
This way we will still get some important warnings for .NET 5 such as
`targetSdkVersion` or `minSdkVersion` that need to be changed in the
`AndroidManifest.xml` file.
I also fixed up `LastBuildOutput`, we needed the value for .NET 5
MSBuild tests and I removed unnecessary usage of `yield return`.
dfdbe08 to
39e3154
Compare
Context: https://github.com/dotnet/designs/blob/master/accepted/2020/net5/net5.md Historically, Xamarin.Android has used `$(TargetFrameworkVersion)` to control the `Mono.Android.dll` binding which is used in apps, and was treated as the Android version number, e.g. `$(TargetFrameworkVersion)`=v5.0 caused Xamarin.Android pull in the `Mono.Android.dll` with bindings for *Android* 5.0 (API-21). With .NET 5, `$(TargetFrameworkVersion)` *instead* is the version of .NET, i.e. .NET 5 will have `$(TargetFrameworkVersion)`=v5.0. The (new?) `$(TargetPlatformVersion)` MSBuild property will now control which `Mono.Android.dll` binding version should be used. Unfortunately, not everything within the Xamarin.Android build system is cognizant of this change. Consequently, when building within a .NET 5 environment, *all* builds will emit this XA1008 warning: warning XA1008: The TargetFrameworkVersion (Android API level 21) is lower than the targetSdkVersion (29). Please increase the `$(TargetFrameworkVersion)` or decrease the `android:targetSdkVersion` in the `AndroidManifest.xml` so that the API levels match. The XA1008 warning is emitted because Google Play requires a minimum version of API-29 (Android v10.0), and `$(TargetFrameworkVersion)` was previously used to infer a minimum API level, and Android v5.0/API-21 is less than the required API-29. To fix this, I modified the `<CheckGoogleSdkRequirements/>` MSBuild task so that: 1. `CheckGoogleSdkRequirements.TargetFrameworkVersion` is optional. 2. A new `CheckGoogleSdkRequirements.ApiLevel` property is available, and allows explicitly providing the API level. In .NET 5 builds, `CheckGoogleSdkRequirements.TargetFrameworkVersion` won't be set; `CheckGoogleSdkRequirements.ApiLevel` will instead be set based on `$(_AndroidApiLevel)`. This way we will still get some important warnings for .NET 5 such as `targetSdkVersion` or `minSdkVersion` that need to be changed in the `AndroidManifest.xml` file. I also fixed up `LastBuildOutput`, we needed the value for .NET 5 MSBuild tests and I removed unnecessary usage of `yield return`.
In our current .NET 5 builds, you always hit:
It is giving a warning for Google Play, because
$(TargetFrameworkVersion)is equal to 5.0.To fix this, I modified the
<CheckGoogleSdkRequirements/>MSBuildtask so that
TargetFrameworkVersionis optional. For .NET 5 builds,we can pass in
$(_AndroidApiLevel)instead.This way we will still get some important warnings for .NET 5 such as
targetSdkVersionorminSdkVersionthat need to be changed in theAndroidManifest.xmlfile.I also fixed up
LastBuildOutput, we needed the value for .NET 5MSBuild tests and I removed unnecessary usage of
yield return.