Commit 94451e6
authored
[Xamarin.Android.Build.Tasks] case-insensitive Legacy Designer fixup (#8376)
Context: 628d6cb
Context: dc3ccf2
We have a very odd situation with the
[`Xamarin.CommunityToolkit.MauiCompat` NuGet package][0]:
The NuGet package ships with a file `.net/__res_name_case_map.txt`
(628d6cb) in `Xamarin.CommunityToolkit.MauiCompat.aar` which contains
the case map changes for the `@(AndroidResource)` items. The purpose
of this file is to allow the user to use PascalCase (or any case) names
in C# code, while the Android Resource compilation is left as all
lowercase. This is because Android requires that file-backed resource
names consist of only lowercase letters.
The contents of this file includes:
Resources/Layout/CameraFragment.axml;layout/camerafragment.xml
which tells us that the Android `R.layout.camerafragment` resource id
should be "bound" as `Resouce.Layout.CameraFragment`, which allows
[`CameraFragment.android.cs` to build][1]:
public override AView? OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) =>
inflater.Inflate(Resource.Layout.CameraFragment, null);
However, when we look at the IL that comes from the NuGet package we
see the only lowercase `camerafragment`:
ikdasm ~/.nuget/packages/xamarin.communitytoolkit.mauicompat/2.0.2-preview1013/lib/net6.0-android31.0/Xamarin.CommunityToolkit.MauiCompat.dll| grep Layout::camerafragment
…
IL_0131: stsfld int32 Xamarin.CommunityToolkit.MauiCompat.Resource/Layout::camerafragment
…
IL_0001: ldsfld int32 Xamarin.CommunityToolkit.MauiCompat.Resource/Layout::camerafragment
For some reason as part of the XamarinCommunityToolkit build
[the following script][2] was run on the code:
sed -i '' 's/MauiCompat.Resource.Layout.CameraFragment/MauiCompat.Resource.Layout.camerafragment/g' ./src/CommunityToolkit/Xamarin.CommunityToolkit.MauiCompat/**/CameraFragment.android.cs
This changes `Resource.Layout.CameraFragment` to
`Resource.Layout.camerafragment`, apparently because *something* is
renaming [`CameraFragment.axml`][3] to `camerafragment.axml` *after*
`__res_name_case_map.txt` is generated, but before
`CameraFragment.android.cs` is compiled.
The NuGet still includes the `.aar` with the case map changes, which
are now inconsistent with the assembly contents.
I'm not sure why XamarinCommunityToolkit does all this.
The result of the above XamarinCommunityToolkit build and packaging
behavior is that it interacts badly with the new net8.0-android
Resource Designer Assembly (dc3ccf2) work, with a build-time error:
error XA8000: Could not find Android Resource ‘@layout/camerafragment’. Please update @(AndroidResource) to add the missing resource.
This is because we are looking for the lowercase version of the
resource in the Designer assembly property list, but because of the
remap file we only know about the PascalCase version.
As a workaround, fallback to a *case-insensitive* resource name
lookup if a case-sensitive lookup fails.
[0]: https://www.nuget.org/packages/Xamarin.CommunityToolkit.MauiCompat/
[1]: https://github.com/xamarin/XamarinCommunityToolkit/blob/5a6062f3c3543acda3c36ca4683cd8fc7fe86ba7/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/CameraView/Android/CameraFragment.android.cs#L129
[2]: https://github.com/xamarin/XamarinCommunityToolkit/blob/5a6062f3c3543acda3c36ca4683cd8fc7fe86ba7/MauiCompat.sh#L561
[3]: https://github.com/xamarin/XamarinCommunityToolkit/blob/5a6062f3c3543acda3c36ca4683cd8fc7fe86ba7/src/CommunityToolkit/Xamarin.CommunityToolkit/Resources/Layout/CameraFragment.axml1 parent a423246 commit 94451e6
File tree
1 file changed
+12
-3
lines changed- src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner
1 file changed
+12
-3
lines changedLines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | | - | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| |||
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
120 | 123 | | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
153 | 157 | | |
154 | 158 | | |
155 | 159 | | |
156 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
157 | 166 | | |
158 | 167 | | |
159 | 168 | | |
| |||
0 commit comments