dotnet / dotnet/android

Layout binding generator produces invalid C# namespaces for Material Components .NET 9 Android projects

Open
#10,349 2 comments 1 reaction 0 assignees View on GitHub
Area: App+Library Build
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 19h
Merged PRs (30d)
252

Description

### Android framework version

net9.0-android

### Affected platform version

.NET 9

### Description

When using .NET 9 for Android with `true`, the generated layout binding code (g.cs) incorrectly maps Java class names for Xamarin.Google.Android.Material to non-existent C# namespaces.

For example, in my layout XML:

The generated code produces:

// Type fixed up from 'com.google.android.material.button.MaterialButton' to 'Android.Material.Button.MaterialButton'
public Android.Material.Button.MaterialButton open_sdlxliff => FindView(...);

However, the correct C# type is:

Google.Android.Material.Button.MaterialButton

as provided by the Xamarin.Google.Android.Material NuGet package.

This results in the following build error:

error CS0234: The type or namespace name 'Material' does not exist in the namespace 'Android' (are you missing an assembly reference?)

### Steps to Reproduce

To Reproduce

1. Create a .NET 9 Android project.
2. Add true to the .csproj.
3. Install Xamarin.Google.Android.Material
3. Add a MaterialButton to a layout XML file.
4. Build the project.
5. Observe that the generated binding code references Android.Material.Button.MaterialButton, which does not exist.

Expected behaviour

The generator should map third-party and Material Components views to their correct C# namespaces, e.g.:

Google.Android.Material.Button.MaterialButton open_sdlxliff => FindView(...);

I also saw the same issue with:

```

```

Getting produced as:

```
// Declared in: Resources/layout/sdlxliff_view.xml:(22:6)
// Type fixed up from 'androidx.core.widget.NestedScrollView' to 'Androidx.Core.Widget.NestedScrollView'. Element defined in Resources/layout/sdlxliff_view.xml:(22:6)
public Androidx.Core.Widget.NestedScrollView content => FindView (global::PocketCat.Android.Resource.Id.content, ref __content);

```

When it should be` Android.X.Core.Widget.NestedScrollView`. (Capital X)

So far to get around this I am using `xamarin:managedType="Google.Android.Material.BottomNavigation.BottomNavigationView"` and it's fine, it compiles but this is far from ideal having to do it for every single component.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.