-
Notifications
You must be signed in to change notification settings - Fork 549
[Microsoft.Android.Ref] support for older targetSdkVersion #4873
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
[Microsoft.Android.Ref] support for older targetSdkVersion #4873
Conversation
Currently, if you build a .NET 5 project that has `targetSdkVersion="29"` (older than 30): error XA5207: Could not find android.jar for API level . This means the Android SDK platform for API level is not installed. Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the Xamarin.Android project to target an API version that is installed. (C:\Users\jopepper\android-toolchain\sdk\platforms\android-\android.jar missing.) A lot of `string.Empty` appears in the error messages... This is because we only have one `AndroidApiInfo.xml`: <AndroidApiInfo> <Id>30</Id> <Level>30</Level> <Name>R</Name> <Version>v11.0</Version> <Stable>True</Stable> </AndroidApiInfo> And so calls like `MonoAndroidHelper.SupportedVersions.GetApiLevelFromId` won't work for API 29, because API 29 is unknown. To fix this, we should ship *all* of the `AndroidApiInfo.xml` files in the `Microsoft.Android.Ref.nupkg`, such as: * `ref\net5.0\Java.Interop.dll` * `ref\net5.0\Mono.Android.dll` * `ref\net5.0\v10.0\AndroidApiInfo.xml` * `ref\net5.0\v11.0\AndroidApiInfo.xml` The code here will continue to work, because it searches recursively: https://github.com/xamarin/xamarin-android-tools/blob/3974fc38c0f25f943b5d3bf0a4e174532a2a60ee/src/Xamarin.Android.Tools.AndroidSdk/AndroidVersions.cs#L45-L46 I added a test verifying app with `targetSdkVersion="29"` work under .NET 5.
I think we should only support targeting a single Android binding version for a given pack? For instance, users who want to target API 29 would need to install and use |
Should you be able to put Right now if we bumped the samples here: https://github.com/xamarin/net6-samples We would have to update every manifest to say |
The |
So this appears to only be broken for specifically API 29, because it isn't listed here: So the question is, do we ship all the |
I had a slight misunderstanding of the original issue at hand. I would agree that we should continue to emit a warning rather than an error in cases where the As for the fix, I think we want to avoid shipping multiple |
Obligatory: Do we need the The purpose behind the In a .NET 5+ environment, That "narrows" the scope to API-Level & ID, e.g. we'll need a mapping from:
A This suggests that we shouldn't ship e.g. Thus we return to the original "bug":
The source of the Is because What if instead it allowed diff --git a/src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs b/src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs
index 1297e51..d2d3b5f 100644
--- a/src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs
+++ b/src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs
@@ -98,11 +98,15 @@ namespace Xamarin.Android.Tools
public string? TryGetPlatformDirectoryFromApiLevel (string idOrApiLevel, AndroidVersions versions)
{
+ string? dir = GetPlatformDirectoryFromId (idOrApiLevel);
+ if (Directory.Exists (dir))
+ return dir;
+
var id = versions.GetIdFromApiLevel (idOrApiLevel);
if (id == null)
return null;
- string? dir = GetPlatformDirectoryFromId (id);
+ dir = GetPlatformDirectoryFromId (id);
if (Directory.Exists (dir))
return dir; Other |
Context: dotnet/android#4873 Although this is related to xamarin-android#4873, it is not the full fix. We probably should list the missing versions here anyway, though.
It looks like we should fix this here instead: dotnet/android-tools#90 |
Context: dotnet/android#4873 Context: dotnet/android#4873 (comment) When xamarin-android is built to support .NET 5, the .NET 5 install directory contains a single `AndroidApiInfo.xml` file: <AndroidApiInfo> <Id>30</Id> <Level>30</Level> <Name>R</Name> <Version>v11.0</Version> <Stable>True</Stable> </AndroidApiInfo> `AndroidVersions`, meanwhile, is setup to read a *set* of `AndroidApiInfo.xml` files (aad97f1) to "dynamically" compute mappings between possible `$(TargetFrameworkVersion)` values, API-levels, and IDs for those API levels. When there is only one such file, if you call: int? apiLevel = androidVersions.GetApiLevelFromId (29); then `apiLevel` will always be `null`, because (at present) `AndroidVersions.KnownVersions` doesn't know about API-29 or API-30. We *could* update `AndroidVersions.KnownVersions` to contain entries for API-29 & API-30, but doing so means that we reintroduce the scenario that `AndroidVersions` was added to help defend against: a need/requirement to update `AndroidVersions.KnownVersions` *every time* a new API level was released, lest ~everything break. We *don't* want to require `AndroidVersions.KnownVersions` updates. To allow a .NET 5-like environment to work *without* updating `KnownVersions`, update the various `GetApiLevelFromId()` methods to return the incoming API level as a fallback. If `"29"` comes in, then `29` can be returned and assumed to be a valid API level.
Context: dotnet/android#4873 Although this is related to xamarin-android#4873, it is not the full fix. We probably should list the missing versions here anyway, though.
Context: dotnet/android#4873 Although this is related to xamarin-android#4873, it is not the full fix. We probably should list the missing versions here anyway, though.
Currently, if you build a .NET 5 project that has
targetSdkVersion="29"
(older than 30):A lot of
string.Empty
appears in the error messages...This is because we only have one
AndroidApiInfo.xml
:And so calls like
MonoAndroidHelper.SupportedVersions.GetApiLevelFromId
won't work for API 29, because API 29 is unknown.
To fix this, we should ship all of the
AndroidApiInfo.xml
files inthe
Microsoft.Android.Ref.nupkg
, such as:ref\net5.0\Java.Interop.dll
ref\net5.0\Mono.Android.dll
ref\net5.0\v10.0\AndroidApiInfo.xml
ref\net5.0\v11.0\AndroidApiInfo.xml
The code here will continue to work, because it searches recursively:
https://github.com/xamarin/xamarin-android-tools/blob/3974fc38c0f25f943b5d3bf0a4e174532a2a60ee/src/Xamarin.Android.Tools.AndroidSdk/AndroidVersions.cs#L45-L46
I added a test verifying app with
targetSdkVersion="29"
work under.NET 5.