Commit 1abd430
authored
[.NET 5] fix XA1008 warning when $(TargetFrameworkVersion)=v5.0 (#4598)
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`.1 parent 3c94f6f commit 1abd430
File tree
7 files changed
+46
-19
lines changed- src/Xamarin.Android.Build.Tasks
- Microsoft.Android.Sdk/targets
- Tasks
- Tests
- Xamarin.Android.Build.Tests
- Xamarin.ProjectTools/Common
7 files changed
+46
-19
lines changedLines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
64 | 73 | | |
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
27 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 33 | + | |
36 | 34 | | |
37 | | - | |
| 35 | + | |
38 | 36 | | |
39 | 37 | | |
40 | 38 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
| |||
Lines changed: 0 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
550 | 549 | | |
551 | 550 | | |
552 | 551 | | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | 552 | | |
562 | 553 | | |
563 | 554 | | |
| |||
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| |||
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
248 | 257 | | |
0 commit comments