dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 529 forks source link

MAUI Android projects generate an \obj\Debug\net6.0-android\Resource.designer.cs file containing code that assigns values to const identifiers #7724

Open Eilon opened 1 year ago

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @frauenholz on Tuesday, August 30, 2022 3:36:57 AM

When proper, the UpdateIdValues() method has about 59 statements (see Resource.designer - UpdateIdValues() proper.cs)

Something is causing the Android Resource.designer.cs file's UpdateIdValues() method to have 6000+ statements, the majority of which are assignment to const's, thus producing approx 6000+ compiler errors (see Resource.designer - UpdateIdValues() constAssigns.cs)

an example is the line: global::MauiLib1.Resource.Animation.abc_tooltip_enter = global::MauiApp1.Resource.Animation.abc_tooltip_enter;;

where the target of the assignment is declared as: public const int abc_tooltip_enter = 2130771978;

it is likely (but not certain) that this is related to when a MAUI app project references a MAUI library project, I am trying to pin it down

Resource.designer - UpdateIdValues.zip

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @msftbot[bot] on Thursday, September 1, 2022 7:14:39 PM

Hi @frauenholz. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @PureWeen on Thursday, September 1, 2022 7:27:46 PM

@jonathanpeppers @dellis1972 ?

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Friday, September 2, 2022 11:16:27 AM

This is probably because the Library project is setting the AndroidApplication property set to true. We only generate const values for applications, not for libraries. For libraries we generate a static so it can be set.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Friday, September 2, 2022 11:17:40 AM

Can you post the csproj files for both the App and the Library projects?

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Friday, September 2, 2022 11:17:59 AM

@PureWeen I can't add the needinfo label.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @jonathanpeppers on Friday, September 2, 2022 12:17:13 PM

In .NET 6 it could also be OutputType=Exe, we set AndroidApplication=true for that as well.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Friday, September 2, 2022 12:26:45 PM

I tried to repo this using the templates in VSForMac and I get static for the library project. So I guess in this case the library project has an OutputType of Exe.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Friday, September 2, 2022 12:27:55 PM

However setting OutputType to Exe is not all that would need to happen. The library project would also need an AndroidManifest and all the ApplicationId settings.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @frauenholz on Friday, September 2, 2022 1:46:51 PM

repo created at https://github.com/frauenholz/MauiApp_9766 this is a .sln with a MauiApp, a MauiLib with a ContentPage, where the MauiApp AppShell.xaml only ShellContnet is the Lib's ContentPage named NewPage1.xaml. The Android Resource.designer.cs file generated by this .sln on my local machine is attached Resource.designer.zip

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Friday, September 2, 2022 2:49:40 PM

Weird, that repo works locally for me on macOS.

Are you able to provide a diagnostic binlog for us to look at? It would be interesting to see what properties the MauiLib_9766 project is getting when building.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @frauenholz on Friday, September 2, 2022 3:11:15 PM

I observed that after cleaning the solution, and re-building, the Resource.designer.cs file is 732KB. After running the MAUI App in the "Pixel 5 - API 31" emulator, while deploying the app the Resource.designer.cs file increased to 1,654 KB, and has the const assignment compile errors. I am not sure how to generate a binlog from the IDE. The attached file is a save of the Output Window from the IDE, Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.3.3. Running on Windows 10.

Output-Debug MAUI issue 9766.txt

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @msftbot[bot] on Tuesday, September 6, 2022 6:36:13 PM

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @jonpryor on Tuesday, September 13, 2022 5:52:12 PM

I have attempted to repro this issue using https://github.com/frauenholz/MauiApp_9766, and have been unable to cause Resource.designer.cs within to have const statements within the MauiLib_9766 project, even after deploying to a device. It feels like we need something "more" in order to properly repro this. ☹️

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Monday, September 26, 2022 2:56:11 PM

@frauenholz area you able to provide us a complete build tree of a sample app? This should include the bin and obj directories for all the projects. We cannot repo this issue using the sample you provided.

Also does this happen from the command line or just the IDE?

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @frauenholz on Saturday, October 1, 2022 1:40:40 AM

MauiApp_9766.zip (184 MB) on https://drive.google.com/file/d/1-yXG_3Bar_dA6rGB_TB7aWfi57flAT5P/view is a zip of the original sample project repository at https://github.com/frauenholz/MauiApp_9766, and has bin and obj directories and other build content. Please let me know if you need something else.

Eilon commented 1 year ago

Issue moved from dotnet/maui#9766


From @dellis1972 on Saturday, October 1, 2022 9:21:20 PM

That is very confusing. Looking at the source files the MauiLib1 Resource.designer.cs contains static fields which is expected. The assembly itself has static fields again expected.

So I am not sure why you are getting a build error.

I'll try to repo again on a Windows machine next week.

DennisWelu commented 1 year ago

I had the same kind of issue and ran across this post on SO that solved my situation: https://stackoverflow.com/questions/73192398/xamarin-resource-designer-cs-generating-const-instead-of-static.

In a quick review of the repro repo for this ticket I don't see the same default namespace scenario, but thought it was worth mentioning.