dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.37k stars 4.75k forks source link

MAUI failed to compile with AOT #81913

Closed succeed318 closed 1 year ago

succeed318 commented 1 year ago

11

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net6.0-android</TargetFrameworks>
        <OutputType>Exe</OutputType>
        <RootNamespace>IotTencent</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>

        <!-- Display name -->
        <ApplicationTitle>XXXXXX</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.companyname.iottencent</ApplicationId>
        <ApplicationIdGuid>2695fcd7-bfcb-4b7b-8eb2-f754a9e0b289</ApplicationIdGuid>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
        <ApplicationTitle>XXX</ApplicationTitle>
        <AndroidPackageFormat>apk</AndroidPackageFormat>
               <EnableLLVM>False</EnableLLVM>

        <RunAOTCompilation>True</RunAOTCompilation>
        <PublishTrimmed>True</PublishTrimmed>

    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-android|AnyCPU'">
      <EnableLLVM>False</EnableLLVM>
    </PropertyGroup>
    <ItemGroup>
        <!-- App Icon -->
        <MauiSplashScreen Include="Resources\Splash\splash.png" />

        <!-- Splash Screen -->

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
        <None Remove="Resources\AppIcon\appicon.png" />
        <None Remove="Resources\Fonts\iconfont.ttf" />
        <None Remove="Resources\Splash\splash.png" />
    </ItemGroup>

    <ItemGroup>
        <MauiIcon Include="Resources\AppIcon\appicon.png" BaseSize="128,128" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
        <PackageReference Include="TencentCloudSDK" Version="3.0.679" />
    </ItemGroup>

    <ItemGroup>
        <None Update="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
        <None Update="Resources\Splash\splash11.svg" Color="#512BD4" BaseSize="128,128" />
    </ItemGroup>

    <ItemGroup>
        <MauiXaml Update="Views\Home.xaml">
            <Generator>MSBuild:Compile</Generator>
        </MauiXaml>
        <MauiXaml Update="Views\Start.xaml">
            <Generator>MSBuild:Compile</Generator>
        </MauiXaml>
    </ItemGroup>

</Project>

use follow config:

<RunAOTCompilation>True</RunAOTCompilation>
<PublishTrimmed>True</PublishTrimmed>

<ItemGroup>
        <PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
        <PackageReference Include="TencentCloudSDK" Version="3.0.679" />
</ItemGroup>
  1. Create a MAUI APP project with VS2022(Version 17.4.4)
  2. install TencentCloud.dll from nuget;
  3. direct publish project, it takes very long,long time; about three hours. finally compiler fail.
jsuarezruiz commented 1 year ago

@jonathanpeppers Thoughts?

jonathanpeppers commented 1 year ago

@jsuarezruiz the error message in the screenshot has the same Assertion table_size error as this one:

https://github.com/dotnet/runtime/issues/81271

succeed318 commented 1 year ago

How do I generate apk using the default configuration; Use the following configuration to generate the APK:

<RunAOTCompilation>True</RunAOTCompilation>
<PublishTrimmed>True</PublishTrimmed>

What should i change?

succeed318 commented 1 year ago

@jonathanpeppers

Change to the following configuration, can be generated normally. The resulting apk is about 60MB.

<RunAOTCompilation>False</RunAOTCompilation>
<PublishTrimmed>False</PublishTrimmed>

image

jonathanpeppers commented 1 year ago

RunAOTCompilation=false would be all you need to turn off AOT.

PublishTrimmed=false turns off the trimmer/linker, that probably isn't solving anything and would make the app large (as you noticed).

danielancines commented 1 year ago

Hi guys,

I'm getting the same error, any thoughts? But in my case, I'm getting error with a brand new Maui project.

jonathanpeppers commented 1 year ago

@danielancines I would file a new issue, everyone here is getting:

* Assertion at D:\a\_work\1\s\src\mono\mono\mini\aot-compiler.c:11219, condition `table_size < 65000' not met 

And it's not happening with new projects.

danielancines commented 1 year ago

@jonathanpeppers Using the command dotnet publish -r win-x64 -c Release -f net7.0-windows10.0.19041.0 I'm getting this error on a brand new Maui project: dotnet\sdk\7.0.102\Sdks\Microsoft.DotNet.ILCompiler\build\Microsoft.NETCore.Native.targets(278,5): error MSB3073: The command ""C:\Users\ancineda\.nuget\packages\[runtime.win](http://runtime.win/)-x64.microsoft.dotnet.ilcompiler\7.0.2\tools\\ilc" @"obj\Release\net7.0-windows10.0.19041.0\win-x64\native\Maui.AOT.ilc.rsp"" exited with code 1. [C:\code\Maui.AOT\Ma ui.AOT\Maui.AOT.csproj::TargetFramework=net7.0-windows10.0.19041.0]

S.O: Windows 10 Visual Studio 2022 - 17.4.4

lewing commented 1 year ago

looks like https://github.com/dotnet/runtime/issues/81271

drossoft commented 1 year ago

Im my case, it happens when I add Microsoft.Graph (5.11.0)

Visual Studio Community 17.6.1

Error Precompiling failed for C:\git\MyProject\MyProject\obj\Release\net7.0-android\android-arm64\linked\Microsoft.Graph.dll with exit code -1073740791. Mono Ahead of Time compiler - compiling assembly C:\git\MyProject\MyProject\obj\Release\net7.0-android\android-arm64\linked\Microsoft.Graph.dll AOTID EA8EE00C-DBA5-6597-5F0E-0883CCE33C29 Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\7.0.86\Sdk\maui.aotprofile' Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\7.0.86\Sdk\maui-blazor.aotprofile' Added 0 methods from profile. Added 0 methods from profile.

The same error appears 4 times, for android-arm64, android-x86, android-x64 and android-arm

vargaz commented 1 year ago

https://github.com/dotnet/runtime/issues/85917

lewing commented 1 year ago

should be fixed by https://github.com/dotnet/runtime/pull/85952