dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

Android Release build - slow and ends with errors, blocker from xamarin migration #12426

Closed LukasKuchta closed 1 year ago

LukasKuchta commented 1 year ago

Description

Hi, we have enterprise app and migrating from xamarin to MAUI. But several problems appears when we started to migrate

When trying to buld android RELESASE buld is very slow in minutes 10 - 20 and no end or errors occured. I attached two files one is for SampleApp with MAUI robot, no code added and second is from our enterprise app (ends with error).

Android debug is ok.

Same problem for template maui app and similar for our.

We have two build machines win and mac and same behaviour.

iOS release is working fine.

It is blocker for us to migrate from xamarin. Thanks for advice.

Logs attached.

BuildLog_SKOffice_MAUI_Release_2022-01-05_08-54.txt

android_release_build.txt

Steps to Reproduce

  1. Create MAUI sample App from VS template
  2. Switch to Release build
  3. Try to make build by build/rebuild button

Link to public reproduction project repository

https://github.com/LukasKuchta/MauiContextMenu

Version with bug

6.0 Release Candidate 2 or older

Last version that worked well

6.0 Release Candidate 2 or older

Affected platforms

Android

Affected platform versions

android independent

Did you find any workaround?

No workaround found.

Relevant log output

atached
LukasKuchta commented 1 year ago

It is tested on .net7

rachelkang commented 1 year ago

@jonathanpeppers

jonathanpeppers commented 1 year ago

Can you attach a .binlog of this build? Add -bl to your command, and it should create a msbuild.binlog file in the current directory.

jonathanpeppers commented 1 year ago

Ok, this could be fixed by: https://github.com/xamarin/xamarin-android/commit/929e7012410233e6814af369db582f238ba185ad

LukasKuchta commented 1 year ago

Binlogs are attached. Build with AOT enabled ends up 1:50s with AOT enabled 39:11

binlogs.zip

Thanks for check

jonathanpeppers commented 1 year ago

It looks like the cause is that CommunityToolkit.Mvvm is marked as trimmable:

https://github.com/CommunityToolkit/dotnet/blob/2edbb0a0a25a046e751b11f0b48baac2e559d957/src/Directory.Build.targets#L13

As a workaround, you might try AndroidLinkSkip=CommunityToolkit.Mvvm. But this might not work, since they have marked this assembly trimmable from the inside (C# custom attribute).

The real fix is https://github.com/xamarin/xamarin-android/commit/929e7012410233e6814af369db582f238ba185ad, which is shipping in the next .NET 7 service release.

ghost commented 1 year ago

Hi @LukasKuchta. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.

ghost commented 1 year ago

Hi @LukasKuchta. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

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.

mattleibow commented 1 year ago

@jonathanpeppers is this going out in the next release that we are working on now? Or the one after that?

jonathanpeppers commented 1 year ago

The one we are working on now.

LukasKuchta commented 1 year ago

Our workaround is disable AOT by those lines in csproj. For now it is enough and we will wait for next release. Thansk

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
<PublishTrimmed>False</PublishTrimmed>
<RunAOTCompilation>False</RunAOTCompilation>
</PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-android|AnyCPU'">
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
</PropertyGroup>