-
Notifications
You must be signed in to change notification settings - Fork 534
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
[XABT] Prefer SupportedOSPlatformVersion
over minSdkVersion
#8026
Conversation
c13f092
to
b70ed5f
Compare
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs
Outdated
Show resolved
Hide resolved
b70ed5f
to
85ea94c
Compare
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs
Outdated
Show resolved
Hide resolved
I noticed that we were not writing a valid `minSdkVersion` value to the generated `AndroidManifest.xml` file for projects which included a manifest that declared a `targetSdkVersion`. In these cases, we would always write a `minSdkVersion` of `19` to the manifest file, as this is the min version that our NDK supports. Fix this to always write the value of `$(SupportedOSPlatformVersion)`. If this value is not explicitly set in the project file, it will default to `$(TargetPlatformVersion)`. A couple of multidex related tests have been added to the ignore list as they are only valid with a minSdkVersion of 20 or lower.
434a36c
to
2d9d8ee
Compare
NDKMinimumApiAvailable
over SupportedOSPlatformVersion
NDKMinimumApiAvailable
over SupportedOSPlatformVersion
SupportedOSPlatformVersion
over minSdkVersion
message: Properties.Resources.XA4216_MinSdkVersion, | ||
messageArgs: new object [] { min_sdk?.Value, XABuildConfig.NDKMinimumApiAvailable } | ||
); | ||
if (min_sdk != null) { |
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.
Aside: the amount of indentation going on here has my crying out for a helper method 3 levels of indentation ago…
} | ||
if (target_sdk != null && (!int.TryParse (target_sdk.Value, out int targetSdkVersion) || targetSdkVersion < XABuildConfig.NDKMinimumApiAvailable)) { | ||
if (target_sdk != null && (!int.TryParse (target_sdk.Value, out int targetSdkVersion) || targetSdkVersion < XABuildConfig.AndroidMinimumDotNetApiLevel)) { |
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.
Similar/different to https://github.com/xamarin/xamarin-android/pull/8026/files#r1199283399 , if targetSdkVersion
is < $(AndroidMinimumDotNetApiLevel)
, should this be an error?
This doesn't feel reasonable, and I wonder what Java would do with:
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="19" />
Maybe this should remain a warning? This just feels bananas to me.
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.
Maybe both XA4216
warnings should be repurposed and converted to errors?
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.
It seems that Android studio does not produce a warning or error when targetSdkVersion
< minSdkVersion
, so we can probably leave the targetSdkVersion
condition untouched.
I'll try to merge XA1036 into XA4216_MinSdkVersion however, as keeping that warning is redundant.
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.
I've repurposed XA4216, it will continue to warn in the case of targetSdkVersion, but will now produce errors for:
- SupportedOSPlatformVersion < minimum version supported
- minSdkVersion < minimum version supported
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs
Show resolved
Hide resolved
...n.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetXamarinProject.cs
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Looks like the only test failures are |
var failedToParseMinSdk = !int.TryParse (min_sdk.Value, out int minSdkVersion); | ||
|
||
if (failedToParseMinSdk || minSdkVersion < XABuildConfig.AndroidMinimumDotNetApiLevel) { | ||
Log.LogCodedError ("XA4216", Properties.Resources.XA4216_MinSdkVersion, min_sdk?.Value, XABuildConfig.AndroidMinimumDotNetApiLevel); |
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.
Is it possible to provide a filename for the error message?
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.
We could extend https://github.com/xamarin/xamarin-android-tools/blob/main/src/Microsoft.Android.Build.BaseTasks/MSBuildExtensions.cs#L142 for the AndroidManifest case, but I don't know of an easy way to report what file is setting SupportedOSPlatformVersion
(it will likely be set in the project file, but could be in a directory.build.props or any other import).
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.
I added dotnet/android-tools#209 so that we can better link to the manifest file in this error.
} | ||
|
||
if (failedToParseMinSdk || minSdkVersion != supportedOsPlatformVersionAsInt) { | ||
Log.LogCodedError ("XA1036", Properties.Resources.XA1036, min_sdk?.Value, SupportedOSPlatformVersion); |
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.
Is it possible to provide a filename for the error message?
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.
I don't know of an easy way to report what file is setting SupportedOSPlatformVersion
(it will likely be set in the project file, but could be in a directory.build.props or any other import).
squash-and-merge commit message: Fixes: https://github.com/xamarin/xamarin-android/issues/8040
I noticed that we were not writing a supported (by us)
`//uses-sdk/@android:minSdkVersion` value to the generated
`AndroidManifest.xml` file for projects which included a manifest
that declared a `targetSdkVersion`. In these cases, we would
always write a `//uses-sdk/@android:minSdkVersion` value of `21` to
`AndroidManifest.xml`, as this is the minimum version that MonoVM
supports.
Fix this to always use the value of `$(SupportedOSPlatformVersion)`
as the `minSdkVersion` attribute in the `AndroidManifest.xml` file.
If this value is not explicitly set in the project file, it will now
default to `$(AndroidMinimumSupportedApiLevel)` instead of
`$(TargetPlatformVersion)`.
The `XA4216` error/warning code has been expanded+repurposed.
The warning that would display when the `minSdkVersion` attribute in
`AndroidManifest.xml` was less than our minimum supported API level
has been converted into an error:
error XA4216: The deployment target '19' is not supported (the minimum is '21').
Please increase (or remove) the //uses-sdk/@android:minSdkVersion value in your project file.
A similar error is now reported when `$(SupportedOSPlatformVersion)`
is less than `$(AndroidMinimumSupportedApiLevel)`
error XA4216: The deployment target '19' is not supported (the minimum is '21').
Please increase the $(SupportedOSPlatformVersion) property value in your project file.
An error condition has been added for when
`//uses-sdk/@android:minSdkVersion` in `AndroidManifest.xml` does not
match `$(SupportedOSPlatformVersion)`:
error XA1036: AndroidManifest.xml //uses-sdk/@android:minSdkVersion '19' does not match the $(SupportedOSPlatformVersion) value '21.0' in the project file (if there is no $(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed).
Either change the value in the AndroidManifest.xml to match the $(SupportedOSPlatformVersion) value, or remove the value in the AndroidManifest.xml (and add a $(SupportedOSPlatformVersion) value to the project file if it doesn't already exist).
A few multidex related tests have been updated/removed as they are
only valid with a minSdkVersion of 20 or lower. |
One comment for the message:
We were previously writing |
* main: [XABT] Prefer `SupportedOSPlatformVersion` over `minSdkVersion` (dotnet#8026) Bump to xamarin/Java.Interop/main@72b041a (dotnet#8089) Bump LibZipSharp to 3.0.0 (dotnet#8061) Bump to xamarin/Java.Interop/main@8c9eece (dotnet#8073) [profiled-aot] update AOT profile for .NET 8 Preview 5 (dotnet#8077) Localized file check-in by OneLocBuild Task (dotnet#8078) Bump to dotnet/installer@6150605bd0 8.0.100-preview.6.23276.3 (dotnet#8083)
Context: #8040
I noticed that we were not writing a valid
minSdkVersion
value to thegenerated
AndroidManifest.xml
file for projects which included amanifest that declared a
targetSdkVersion
. In these cases, we wouldalways write a
minSdkVersion
of19
to the manifest file, as this isthe min version that our NDK supports.
Fix this to always use the value of
$(SupportedOSPlatformVersion)
asthe
minSdkVersion
element in theAndroidManifest.xml
file. If thisvalue is not explicitly set in the project file, it will now default to
$(AndroidMinimumSupportedApiLevel)
instead of$(TargetPlatformVersion)
.The
XA4216
error/warning code has been repurposed.The warning that would display when the
minSdkVersion
element inAndroidManifest.xml
was less than our minimum supported API level hasbeen converted into an error:
An error condition has been added for when the
$(SupportedOSPlatformVersion)
property value is less than$(AndroidMinimumSupportedApiLevel)
:An error condition has been added for when the
minSdkVersion
elementin
AndroidManifest.xml
does not match$(SupportedOSPlatformVersion)
:A few multidex related tests have been updated/removed as they are only
valid with a minSdkVersion of 20 or lower.