Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
Перейти к файлу
Jonathan Peppers 73efcfcad0
[Xamarin.Android.Buid.Tasks] don't set $(PublishSelfContained) for .NET 9 (#8565)
Context: d21e6bf5c5
Context: 8fa5d99341
Context: 0cd963ac03
Context: 95946d2e7f
Context: 964746e83a

Building a `net8.0-android` project with a .NET 9 SDK will fail when
providing an RID:

	> dotnet publish
	# works

	> dotnet publish -r android-arm64
	MSBuild version 17.9.0-preview-23577-01+31108edc1 for .NET
	…
	bin\Debug\dotnet\sdk\9.0.100-alpha.1.23603.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(494,5):
	error NETSDK1112: The runtime pack for Microsoft.Android.Runtime.34.android-arm64 was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'android-arm64'.

Our repo also sets `$(DisableTransitiveFrameworkReferenceDownloads)`
within unit tests (95946d2e), which causes a slightly different error
message:

	error NETSDK1185: The Runtime Pack for FrameworkReference 'Microsoft.Android.Runtime.34.android-arm' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true.

which matches the TODO within 8fa5d993:

>  * A specific case of `dotnet publish -f net8.0-android -r android-arm`
>    is failing with:
> 
>        error NETSDK1185: The Runtime Pack for FrameworkReference 'Microsoft.Android.Runtime.34.android-arm' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true.
> 
>    This is related to `$(AllowSelfContainedWithoutRuntimeIdentifier)`,
>    but I will address in a future PR.  This will likely require .NET 8
>    Android workload changes.

In .NET 8, 0cd963ac0 began setting `$(PublishSelfContained)`=false
as a way to avoid the error:

	Microsoft.NET.RuntimeIdentifierInference.targets(212,5):
	error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly.

Because Android is always self-contained, we set `$(SelfContained)`
through other means (964746e8; `$(SelfContained)` is set as part of the
inner builds), and everything worked.

In .NET 9, other changes were made such that this "workaround" no
longer works.  To fix this, @@rolfbjarne introduced dotnet/sdk@d21e6bf5
and `$(AllowSelfContainedWithoutRuntimeIdentifier)` as a way to fix the
issue going forward in .NET 9.  We are using the new property in .NET 9
since 8fa5d993.

Unfortunately, this leaves one case that is still broken:

 1. Create a new project with `$(TargetFramework)`=net8.0-android
    (i.e. a .NET 8 project)

 2. Using the .NET 9 SDK

 3. Building while specifying a RID, e.g.
 
        dotnet publish -r android-arm64

It seems like, for now, we can just condition our workaround for
.NET 8 and below:

	<PublishSelfContained Condition=" '$(PublishSelfContained)' == '' and $([MSBuild]::VersionLessThan($(NETCoreSdkVersion), '9.0')) ">false</PublishSelfContained>

Making this change locally, both cases work for me:

  * .NET 8 project, .NET 8 SDK: `dotnet publish -r android-arm64`

  * .NET 8 project, .NET 9 SDK: `dotnet publish -r android-arm64`

The only other solution would be to create our own empty
`_CheckForUnsupportedAppHostUsage` target to avoid errors, but that
seems explicitly worse.  We should also backport dotnet/sdk#d21e6bf5
to .NET 8 SDKs, but it will probably take a month for that to ship.

After this is merged and we have a new, nightly .NET 8 build, we can
restore the [`XASdkTests.DotNetPublish()` unit test][0] on main.

[0]: 40cc8eaf78/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs (L202-L205)
2023-12-13 17:00:01 -05:00
.github [ci] use GitOps.ResourceManagement, as FabricBot is decommissioned (#8173) 2023-07-31 14:47:59 -04:00
.vscode [.vscode] use net7.0-android (#7268) 2022-09-07 12:09:50 -04:00
Documentation [Xamarin.Android.Build.Tasks] Update XA5207 for VSCode (#8494) 2023-12-06 10:56:29 -06:00
Localize LEGO: Merge pull request 8587 2023-12-12 12:58:11 -06:00
build-tools [release/8.0.1xx] Bump Android SDK component versions (#8534) 2023-11-28 16:34:15 -05:00
eng Bump to dotnet/installer/release/8.0.1xx@822071c28a 8.0.101-servicing.23578.14 (#8558) 2023-12-04 20:52:47 -06:00
external Bump to dotnet/installer/release/8.0.1xx@35587e8180 8.0.101-servicing.23572.5 (#8491) 2023-11-29 12:19:59 -06:00
samples [Xamarin.Android.Build.Tasks] AutoImport `*.webp` files (#7601) 2022-12-13 07:58:23 -05:00
src [Xamarin.Android.Buid.Tasks] don't set $(PublishSelfContained) for .NET 9 (#8565) 2023-12-13 17:00:01 -05:00
src-ThirdParty [lgtm] Fix LGTM-reported issues (#1074) 2023-02-14 08:08:29 -05:00
tests [tests] add test for Microsoft.Intune (#7926) 2023-11-30 16:05:30 -06:00
tools Convert `/tools` and `/build-tools` projects from `net472` to `$(DotNetStableTargetFramework)` (#7943) 2023-04-12 14:10:39 -05:00
.editorconfig [monodroid] Add native code static checkers and sanitizers (#5094) 2020-10-13 16:01:41 -04:00
.external [release/8.0.1xx] Bump Android SDK component versions (#8534) 2023-11-28 16:34:15 -05:00
.gitattributes [Xamarin.Android.Build.Tasks] Move XA4214 warning text into .resx file (#3900) 2019-12-07 13:58:58 -05:00
.gitignore [ci] Fix test categories for emu smoke tests (#7374) 2022-09-14 20:35:14 -04:00
.gitmodules [Xamarin.Android.Build.Tasks] stop redistributing `apksigner` (#7984) 2023-04-24 12:53:23 -05:00
.lgtm.yml [lgtm] Fix LGTM-reported issues (#1074) 2023-02-14 08:08:29 -05:00
Configuration.Override.props.in [Mono.Android] Bind and enumify API-34 (#8116) 2023-06-26 19:54:45 -04:00
Configuration.props [release/8.0.1xx] Bump Android SDK component versions (#8534) 2023-11-28 16:34:15 -05:00
Directory.Build.props [release/8.0.1xx] stable 34.0.x branding (#8361) 2023-09-22 14:28:40 -05:00
Directory.Build.targets Bump to xamarin/xamarin-android-tools/main@fa3711b (#7501) 2022-11-18 08:13:00 -05:00
LICENSE [build] ThirdPartyNotices.txt support (#464) 2018-03-02 09:54:35 -05:00
Makefile Remove more xabuild (#8263) 2023-08-14 15:48:43 -04:00
NuGet.config Bump to dotnet/installer/release/8.0.1xx@35587e8180 8.0.101-servicing.23572.5 (#8491) 2023-11-29 12:19:59 -06:00
README.md [readme] Add aka.ms links for d17.5. (#7935) 2023-04-03 13:05:38 -05:00
SECURITY.md Add SECURITY.md (#5956) 2021-05-24 15:48:07 -04:00
ThirdPartyNotices.txt [monodroid] Build the Xamarin.Android runtime for net6 (#5665) 2021-03-02 22:01:01 -05:00
Xamarin.Android-Tests.sln [ci] Parallelize and reduce overhead of MSBuild test stage. (#7850) 2023-03-10 12:12:46 -06:00
Xamarin.Android.BootstrapTasks.sln [build] improve Xamarin.Android.sln usability in VS Windows (#3877) 2019-11-12 11:37:20 +01:00
Xamarin.Android.Build.Tasks.sln [illink] Use latest illink (#5604) 2021-02-11 18:20:49 +01:00
Xamarin.Android.code-workspace [build] Update VSCode Support (#5987) 2021-07-08 13:27:40 -04:00
Xamarin.Android.sln [Xamarin.Android.Build.Tasks] remove Xamarin.Android.Legacy.targets and friends (#7985) 2023-04-24 16:23:09 -05:00
before.Xamarin.Android.sln.targets [build] fix for case-sensitive file systems (#5381) 2020-12-08 10:25:25 -05:00
build.cmd Remove more xabuild (#8263) 2023-08-14 15:48:43 -04:00
build.sh [build] Update VSCode Support (#5987) 2021-07-08 13:27:40 -04:00
dotnet-local.cmd dotnet-local & net8: local dotnet first in PATH (#8222) 2023-08-12 06:50:58 -04:00
dotnet-local.sh dotnet-local & net8: local dotnet first in PATH (#8222) 2023-08-12 06:50:58 -04:00
global.json [One .NET] Target net6.0 instead of netcoreapp3.1 (#5891) 2021-04-30 09:27:12 -05:00
mono.snk [build] Remove Mono submodule (#3371) 2019-07-25 12:04:22 -04:00
msfinal.pub [build] Remove Mono submodule (#3371) 2019-07-25 12:04:22 -04:00
product.snk [Mono.Android, Mono.Android.Export] Sign assemblies. (#29) 2016-05-10 16:29:33 +01:00

README.md

.NET Android banner

.NET Android

.NET Android provides open-source bindings of the Android SDK and tooling for use with .NET managed languages such as C#. This ships as an optional .NET workload for .NET 6+ that can be updated independently from .NET in order to respond to external dependency updates like new Android platform and tooling.

While .NET Android is an essential part of MAUI, it is still fully supported to be used independently for native Android development using .NET.

This repository is also home to the classic Xamarin.Android product.

Support

.NET Android is now part of .NET 6+ and follows the same support lifecycle as the MAUI Support Lifecycle.

Support for classic Xamarin.Android will end on May 1, 2024 as per the Xamarin Support Policy:

Xamarin support will end on May 1, 2024 for all classic Xamarin SDKs. Android 13 will be the final version classic Xamarin.Android will target.

Build Status

Platform Status
OSS macOS OSS macOS x86_64
OSS Ubuntu OSS Linux/Ubuntu x86_64

Downloads

Current

.NET Android ships as a workload through the dotnet workload system in .NET 6+. See the workload documentation for installation commands.

Classic Xamarin.Android installers are available here:

Platform Link
Commercial Xamarin.Android 13.2 (d17-5) for Windows+Visual Studio 2022 Download
Commercial Xamarin.Android 13.2 (d17-5) for macOS Download
OSS Xamarin.Android (main) for Ubuntu* OSS Linux/Ubuntu x86_64

* Please note that the OSS installer packages are not digitally signed.

Previous Releases are also available for download.

Contributing

If you are interested in fixing issues and contributing directly to the code base, please see the following:

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

Feedback

Discord

License

Copyright (c) .NET Foundation Contributors. All rights reserved. Licensed under the MIT License.