Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] Honour the AndroidGenerateResourceDesigner setting #7721

Merged
merged 4 commits into from
Jan 24, 2023

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Jan 20, 2023

Currently setting AndroidGenerateResourceDesigner to false does NOT stop the new resource designer assembly
from being generated.
We should change this so that library projects which want to use this setting (as per the docs) to disable
the resoruce designer then it should work. So if the AndroidGenerateResourceDesigner is set to fail we will NOT generate
the intermediate __Microsoft.Resource.Designer.Assembly.cs (or .fs) file. But we will still generate the assembly.
This means the Resource class will not be part of the built assembly and will not be available.

A unit test has been updated to test this change.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

So here is a combination I think might break:

  1. Class library where I don't want any resource designer, so I set $(AndroidGenerateResourceDesigner) to false
  2. Reference a class library that does have a resource designer

So think something might need to happen here (or only apply to application projects?):

https://github.com/xamarin/xamarin-android/blob/baa5a739b957d724df3a33f001e4e1cde914cee5/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Resource.Designer.targets#L143-L147

I think dotnet/maui will have this case.

@dellis1972
Copy link
Contributor Author

So here is a combination I think might break:

  1. Class library where I don't want any resource designer, so I set $(AndroidGenerateResourceDesigner) to false
  2. Reference a class library that does have a resource designer

So think something might need to happen here (or only apply to application projects?):

https://github.com/xamarin/xamarin-android/blob/baa5a739b957d724df3a33f001e4e1cde914cee5/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Resource.Designer.targets#L143-L147

I think dotnet/maui will have this case.

Hmm. This is a good point. Currently you'd get an error since it won't let you do that.
That does suggest we can't turn this off....

@dellis1972
Copy link
Contributor Author

I'm gonna have to have a think about this one. Maybe leaving the setting on and just not generating anything in the assembly would be better. The downside of that is you will always get an assembly.

@jonathanpeppers
Copy link
Member

The other thing I was setting in MAUI, was new public APIs for things like:

Microsoft.Maui.Graphics.Skia.Resource
Microsoft.Maui.Graphics.Skia.Resource.Resource() -> void

I had to add these to a list to make their API analyzer happy.

So maybe we could avoid generating the __Microsoft.Android.Resource.Designer.cs file?

@dellis1972
Copy link
Contributor Author

So maybe we could avoid generating the __Microsoft.Android.Resource.Designer.cs file?

Good idea, I updated this PR to do that and it seems to work.
Also updated the unit test.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

LGTM if it ends up green now. 👍

@jonpryor
Copy link
Member

[Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (#7721)

Context: dc3ccf28cdbe9f8c0a705400b83c11a85c81a980
Context: https://github.com/dotnet/maui/pull/12520

When `_Microsoft.Android.Resource.Designer.dll` is used (dc3ccf28)
and [`$(AndroidGenerateResourceDesigner)`][0]=False, the
`__Microsoft.Android.Resource.Designer.cs` file is still generated,
which is *equivalent* to `Resource.designer.cs`.  This causes a
`Resource` type to be generated.

This showed up when attempting to bump MAUI to use xamarin-android
for .NET 8 (dotnet/maui#12520), which [introduced][1] *lots* of
`*.Resource` types which are *not desirable*.

Fix this so that when `$(AndroidGenerateResourceDesigner)`=False the
`__Microsoft.Android.Resource.Designer.*` files are *not* created.
This prevents `*.Resource` types from being added to the assembly.

Note that `_Microsoft.Android.Resource.Designer.dll` is still created
at build time.

A unit test has been updated to test this change.

[0]: https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-properties#androidgenerateresourcedesigner
[1]: https://github.com/dotnet/maui/pull/12520/commits/2e4981257c1203a9dea935b4b39979859b770c33

@jonpryor jonpryor merged commit 953cd19 into dotnet:main Jan 24, 2023
@dellis1972 dellis1972 deleted the nodesigner branch January 24, 2023 18:04
jonathanpeppers added a commit to dotnet/maui that referenced this pull request Jan 24, 2023
Changes: dotnet/android@8a20803...c1efcb5
Changes: xamarin/xamarin-macios@df0151d...6b1b9f3
Changes: dotnet/installer@8c1708f...9962c6a
Changes: dotnet/runtime@5108757...5da4a9e
Changes: dotnet/emsdk@aecb1c7...66b9845

Updates:

* Microsoft.Android.Sdk.Windows: from 34.0.0-preview.1.50 to 34.0.0-preview.1.127
* Microsoft.iOS.Sdk: from 16.1.585-net8-p1 to 16.2.126-net8-p1
* Microsoft.Dotnet.Sdk.Internal: from 8.0.100-alpha.1.22526.2 to 8.0.100-alpha.1.23063.11
* Microsoft.NETCore.App.Ref: from 8.0.0-alpha.1.22524.5 to 8.0.0-alpha.1.23058.2
* Microsoft.NET.Workload.Emscripten.net7.Manifest-8.0.100: from 8.0.0-alpha.1.22510.1 to 8.0.0-alpha.1.22620.1

~~ Workloads ~~

The .NET SDK has a workaround for `microsoft.net.workload.mono.toolchain`:

dotnet/sdk@f5cb7e3

* HACK: copy folder to `microsoft.net.workload.mono.toolchain.net8` for now until this is resolved.

~~ Android ~~

The biggest changes now in xamarin-android/main are:

* Android enums now have appropriate `[SupportedOSPlatform]` attributes.
  This caused various new warnings in MAUI.

Example:

    src/Essentials/test/DeviceTests/Tests/Vibration_Tests.cs(16,62): error CA1416: This call site is reachable on: 'Android' 21.0 and later. 'BuildVersionCodes.M' is only supported on: 'android' 23.0 and later.
    src/Essentials/test/DeviceTests/Tests/Vibration_Tests.cs(34,62): error CA1416: This call site is reachable on: 'Android' 21.0 and later. 'BuildVersionCodes.M' is only supported on: 'android' 23.0 and later.

* Android now has a new implementation of `Resource.designer.cs`:

dotnet/android@dc3ccf2

We had to make various API changes for a new `Resource` type. Some we we be able to get rid of in the future, after we get:

dotnet/android#7721

* Remove IsMarshmallowOrNewer, IsNougatOrNewer

It appears the analyzer can't tell these values are using `OperatingSystem.IsAndroidVersionAtLeast()`.

It seems we can just use this API directly instead.

* Allow `$(AndroidEnableMarshalMethods)` again

This has the fix:

dotnet/android@22f10b2

Fixes: #11605

~~ Other changes ~~

* [essentials, compatibility] disable trimming for netstandard

* Minor iOS API Changes

* Fix CA2200 in test

Fixes:

    src\Controls\tests\Core.UnitTests\ImageButtonUnitTest.cs(215,6): error CA2200: Re-throwing caught exception changes stack information

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 25, 2023
* main:
  [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734)
  Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738)
  [build] bump `$(AndroidNet7Version)` (dotnet#7737)
  Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718)
  [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721)
  Bump to xamarin/monodroid@50faac94 (dotnet#7725)
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 26, 2023
* main: (32 commits)
  [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734)
  Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738)
  [build] bump `$(AndroidNet7Version)` (dotnet#7737)
  Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718)
  [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721)
  Bump to xamarin/monodroid@50faac94 (dotnet#7725)
  Revert "[Xamarin.Android.Build.Tasks] fix cases of missing `@(Reference)` (dotnet#7642)" (dotnet#7726)
  [marshal methods] Properly support arrays of arrays (dotnet#7707)
  Bump to dotnet/installer@9962c6a 8.0.100-alpha.1.23063.11 (dotnet#7677)
  [Actions] Add action to bump the hash used for the unified pipeline (dotnet#7712)
  Bump to xamarin/xamarin-android-tools/main@099fd95 (dotnet#7709)
  [ci] Move build stages into yaml templates (dotnet#7553)
  [Xamarin.Android.Build.Tasks] fix NRE in `<GenerateResourceCaseMap/>` (dotnet#7716)
  [ci] Pass token when building Designer tests (dotnet#7715)
  [Mono.Android] Android.Telecom.InCallService.SetAudioRoute() + enum (dotnet#7711)
  [Mono.Android] Fix some incorrect enums. (dotnet#7670)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer namespace (dotnet#7681)
  LEGO: Merge pull request 7713
  [Xamarin.Android.Build.Tasks] lazily populate Resource lookup (dotnet#7686)
  [Xamarin.Android.Build.Tasks] skip XA1034 logic in some cases (dotnet#7680)
  ...
rmarinho pushed a commit to dotnet/maui that referenced this pull request Jan 27, 2023
Changes: dotnet/android@8a20803...c1efcb5
Changes: xamarin/xamarin-macios@df0151d...6b1b9f3
Changes: dotnet/installer@8c1708f...9962c6a
Changes: dotnet/runtime@5108757...5da4a9e
Changes: dotnet/emsdk@aecb1c7...66b9845

Updates:

* Microsoft.Android.Sdk.Windows: from 34.0.0-preview.1.50 to 34.0.0-preview.1.127
* Microsoft.iOS.Sdk: from 16.1.585-net8-p1 to 16.2.126-net8-p1
* Microsoft.Dotnet.Sdk.Internal: from 8.0.100-alpha.1.22526.2 to 8.0.100-alpha.1.23063.11
* Microsoft.NETCore.App.Ref: from 8.0.0-alpha.1.22524.5 to 8.0.0-alpha.1.23058.2
* Microsoft.NET.Workload.Emscripten.net7.Manifest-8.0.100: from 8.0.0-alpha.1.22510.1 to 8.0.0-alpha.1.22620.1

~~ Workloads ~~

The .NET SDK has a workaround for `microsoft.net.workload.mono.toolchain`:

dotnet/sdk@f5cb7e3

* HACK: copy folder to `microsoft.net.workload.mono.toolchain.net8` for now until this is resolved.

~~ Android ~~

The biggest changes now in xamarin-android/main are:

* Android enums now have appropriate `[SupportedOSPlatform]` attributes.
  This caused various new warnings in MAUI.

Example:

    src/Essentials/test/DeviceTests/Tests/Vibration_Tests.cs(16,62): error CA1416: This call site is reachable on: 'Android' 21.0 and later. 'BuildVersionCodes.M' is only supported on: 'android' 23.0 and later.
    src/Essentials/test/DeviceTests/Tests/Vibration_Tests.cs(34,62): error CA1416: This call site is reachable on: 'Android' 21.0 and later. 'BuildVersionCodes.M' is only supported on: 'android' 23.0 and later.

* Android now has a new implementation of `Resource.designer.cs`:

dotnet/android@dc3ccf2

We had to make various API changes for a new `Resource` type. Some we we be able to get rid of in the future, after we get:

dotnet/android#7721

* Remove IsMarshmallowOrNewer, IsNougatOrNewer

It appears the analyzer can't tell these values are using `OperatingSystem.IsAndroidVersionAtLeast()`.

It seems we can just use this API directly instead.

* Allow `$(AndroidEnableMarshalMethods)` again

This has the fix:

dotnet/android@22f10b2

Fixes: #11605

~~ Other changes ~~

* [essentials, compatibility] disable trimming for netstandard

* Minor iOS API Changes

* Fix CA2200 in test

Fixes:

    src\Controls\tests\Core.UnitTests\ImageButtonUnitTest.cs(215,6): error CA2200: Re-throwing caught exception changes stack information

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 30, 2023
* main:
  [Xamarin.Android.Build.Tasks] Fix issue where app will not install (dotnet#7719)
  Bump to dotnet/installer@779a644 8.0.100-alpha.1.23070.23 (dotnet#7728)
  LEGO: Merge pull request 7751
  [Mono.Android] Wrap connection exceptions in HttpRequestException (dotnet#7661)
  [Mono.Android] Fix View.SystemUiVisibility enumification (dotnet#7730)
  Bump r8 from 3.3.75 to 4.0.48 (dotnet#7700)
  [monodroid] Prevent overlapped decompression of embedded assemblies (dotnet#7732)
  [xaprepare] Support arm64 emulator components (dotnet#7743)
  Bump SQLite to 3.40.1 (dotnet#7733)
  Bump to xamarin/xamarin-android-binutils/L_15.0.7-5.0.3@6721af4b (dotnet#7742)
  [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734)
  Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738)
  [build] bump `$(AndroidNet7Version)` (dotnet#7737)
  Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718)
  [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721)
  Bump to xamarin/monodroid@50faac94 (dotnet#7725)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2024
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.

3 participants