Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
Перейти к файлу
Dean Ellis 715a36af86
[Microsoft.Android.Sdk.Analysis] Warn on missing activation ctors (#9447)
Fixes: https://github.com/dotnet/android/issues/8410

Context: b3079db44e
Context: https://learn.microsoft.com/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix

Commit b3079db4 added a `Microsoft.Android.Sdk.Analysis.dll` assembly
which contained a [`DiagnosticAnalyzer`][0] to suppress IDE0002
warnings.

Extend that support to add a `CustomApplicationAnalyzer` which checks
for the [`(IntPtr, JniHandleOwnership)`][1] constructor on
[`Android.App.Application`][2] subclasses, as this constructor is
currently required.

If the constructor is missing:

	[Application]
	public class MyApp : Application {
	}

then the app will crash during startup:

	System.NotSupportedException: Unable to activate instance of type MyApp from native handle 0x7ff1f3b468 (key_handle 0x466b26f).

If we find an `Application` subclass that is missing the required
constructor, we'll emit a DNAA0001 warning:

	warning DNAA0001: Application class 'MyApp' does not have an Activation Constructor.

Additionally, provide a `CustomApplicationCodeFixProvider` which will
inject the required constructor into the syntax tree.

Finally, rename the previous `XAD0001` warning to `DNAS0001`.
Our convention is as follows:

  * `DNA`: prefix for .NET for Android messages
  * `A` for *Analyzers*, `S` for *Suppressors*
  * 4 digit code.

[0]: https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.diagnostics.diagnosticanalyzer?view=roslyn-dotnet-4.9.0
[1]: https://learn.microsoft.com/en-us/dotnet/api/android.app.application.-ctor?view=net-android-34.0#android-app-application-ctor(system-intptr-android-runtime-jnihandleownership)
[2]: https://learn.microsoft.com/en-us/dotnet/api/android.app.application?view=net-android-34.0
2024-11-06 14:30:38 -05:00
.gdn
.github
.vscode
Documentation [docs] Sync docs with dotnet/docs-mobile@9ccd7291 (#9474) 2024-10-31 15:02:36 -04:00
Localize
build-tools [docs] Sync docs with dotnet/docs-mobile@9ccd7291 (#9474) 2024-10-31 15:02:36 -04:00
eng
external Bump external/Java.Interop from `87fdb8e` to `2bdf2bc` (#9464) 2024-10-31 09:00:57 -10:00
samples
src [Microsoft.Android.Sdk.Analysis] Warn on missing activation ctors (#9447) 2024-11-06 14:30:38 -05:00
src-ThirdParty
tests
tools
.editorconfig
.external
.gitattributes
.gitignore
.gitmodules
.lgtm.yml
CODE-OF-CONDUCT.md
Configuration.Override.props.in
Configuration.props
Directory.Build.props
Directory.Build.targets
LICENSE.TXT
Makefile
NuGet.config
README.md
SECURITY.md
THIRD-PARTY-NOTICES.TXT
Xamarin.Android-Tests.sln
Xamarin.Android.BootstrapTasks.sln
Xamarin.Android.Build.Tasks.sln
Xamarin.Android.code-workspace
Xamarin.Android.sln [Xamarin.Android.sln] Remove `Java.Interop.NamingCustomAttributes.shproj`. (#9488) 2024-11-06 08:25:35 -06:00
before.Xamarin.Android.sln.targets
build.cmd
build.sh
dotnet-local.cmd
dotnet-local.sh
global.json
msfinal.pub
product.snk

README.md

.NET for Android banner

.NET for Android

.NET for 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.

.NET for Android is part of .NET MAUI, and may also be used independently for native Android development using .NET.

Support

.NET for Android is part of .NET MAUI, since it was introduced in May 2022 as part of .NET 6, and is currently supported as described in the .NET MAUI Support Policy.

Support for Xamarin.Android ended on May 1, 2024 as per the Xamarin Support Policy:

Xamarin support ended on May 1, 2024 for all Xamarin SDKs including Xamarin.Forms. Android API 34 and Xcode 15 SDKs (iOS and iPadOS 17, macOS 14) are the final versions Xamarin targets from existing Xamarin SDKs (i.e. no new APIs are planned).

Follow the official upgrade guidance to bring your Xamarin applications to the latest version of .NET.

Downloads

.NET for Android ships as a workload through the dotnet workload system in .NET 6+.

In its simplest form, .NET for Android can be installed by running:

dotnet workload install android

See the .NET workload documentation for additional installation commands and options.

While no longer supported, Classic Xamarin.Android installers are still available here.

Contributing

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

Feedback

Discord

License

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