Skip to content

Conversation

jonathanpeppers
Copy link
Member

Context: dotnet/android#9973

We introduced a new internal type in Mono.Android.dll:

namespace Microsoft.Android.Runtime;

class ManagedValueManager : JniRuntime.JniValueManager

Causes various C# compiler errors in dotnet/maui:

D:\src\maui\src\Essentials\src\AppActions\AppActions.shared.cs(62,28):
error CS0234: The type or namespace name 'Content' does not exist in the namespace 'Microsoft.Android' (are you missing an assembly reference?)

At some point in .NET 10 (or future), we will likely introduce a public type in Microsoft.Android namespace.

This means MAUI's codebase will need to be fixed in a .NET 10 timeframe, so instead of:

Android.Content.Context content;

This works:

using Android.Content;
//...
Context content;

Because the using Android.Content; directive is scoped outside of a Microsoft.* namespace.

We don't anticipate this to be a problem with customers, because they aren't writing code in Microsoft.* namespaces.

I generally took the approach:

  • Use using Android.Content; if possible.

  • Use global:: if that caused other conflicts.

  • Use using AView = Android.Views.View; in Microsoft.Maui.Controls or other places this is commonly used.

  • Update #if __ANDROID__ to #if ANDROID in a few places.

Context: dotnet/android#9973

We introduced a new `internal` type in `Mono.Android.dll`:

    namespace Microsoft.Android.Runtime;

    class ManagedValueManager : JniRuntime.JniValueManager

Causes various C# compiler errors in dotnet/maui:

    D:\src\maui\src\Essentials\src\AppActions\AppActions.shared.cs(62,28):
    error CS0234: The type or namespace name 'Content' does not exist in the namespace 'Microsoft.Android' (are you missing an assembly reference?)

At some point in .NET 10 (or future), we will likely introduce a
*public* type in `Microsoft.Android` namespace.

This means MAUI's codebase will need to be fixed in a .NET 10
timeframe, so instead of:

    Android.Content.Context content;

This works:

    using Android.Content;
    //...
    Context content;

Because the `using Android.Content;` directive is scoped *outside* of
a `Microsoft.*` namespace.

We don't anticipate this to be a problem with customers, because they
aren't writing code in `Microsoft.*` namespaces.

I generally took the approach:

* Use `using Android.Content;` if possible.

* Use `global::` if that caused other conflicts.

* Use `using AView = Android.Views.View;` in Microsoft.Maui.Controls
  or other places this is commonly used.

* Update `#if __ANDROID__` to `#if ANDROID` in a few places.
@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 2, 2025 20:47
@Copilot Copilot AI review requested due to automatic review settings April 2, 2025 20:47
@jonathanpeppers jonathanpeppers requested review from a team as code owners April 2, 2025 20:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses Android namespace conflicts by adding the global:: qualifier where necessary and updating preprocessor directives (from ANDROID to ANDROID). It also refines type references through using aliases (e.g. AView) to disambiguate between Android and emerging Microsoft.Android types.

  • Updated type instantiations to use global qualifiers to resolve namespace conflicts.
  • Replaced old preprocessor directives with consistent ANDROID symbols.
  • Adjusted using directives and aliases (e.g. AView) across multiple files.

Reviewed Changes

Copilot reviewed 53 out of 53 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Core/src/Handlers/Image/ImageHandler.Android.cs Applied global:: qualifier for Android.Graphics.Rect
src/Core/src/Handlers/Editor/EditorHandler.Android.cs Updated TextAlignment and event argument types with global:: qualification
src/Core/src/Handlers/Button/ButtonHandler.Android.cs Applied global:: for Android.Graphics.PorterDuff.Mode
src/Core/src/Handlers/Border/BorderHandler.Android.cs Switched to using directive for Android.Views and simplified LayerType usage
src/Core/src/Embedding/EmbeddingExtensions.cs Qualified Android.App.Application with global:: to avoid conflicts
src/Core/src/Core/Extensions/ITextInputExtensions.cs Updated method signature for UpdateText with simplified type name
src/Core/src/ActivationState.cs Changed preprocessor directives and simplified Bundle type qualification
src/Core/maps/src/Handlers/Map/MapHandler.Android.cs Updated event arg types with using directive for Android.Views
src/Controls/src/Core/* Various files updated to use the AView alias and qualify Android types to resolve ambiguity
src/BlazorWebView/src/Maui/Android/* Qualified Android.Webkit types and updated layout instantiation

@rmarinho rmarinho merged commit bc0e861 into net10.0 Apr 3, 2025
130 of 134 checks passed
@rmarinho rmarinho deleted the dev/peppers/androidns branch April 3, 2025 15:53
@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants