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

Unable to build with AOT enabled #18839

Closed
Petrarca181 opened this issue Nov 17, 2023 · 8 comments
Closed

Unable to build with AOT enabled #18839

Petrarca181 opened this issue Nov 17, 2023 · 8 comments
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@Petrarca181
Copy link

Description

Can't install Microsoft.DotNet.ILCompiler at all. Getting ths error in my Maui project:
Unable to find package runtime.linux-arm.Microsoft.DotNet.ILCompiler.

Steps to Reproduce

1 Create Fresh maui app
2 enable aot
3build

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

no

Relevant log output

No response

@Petrarca181 Petrarca181 added the t/bug Something isn't working label Nov 17, 2023
@jonathanpeppers
Copy link
Member

What platform are you targeting here?

2 enable aot

What does this mean? AOT is already enabled in Release mode for mobile, for example.

Unfortunately, just saying "AOT" isn't specific enough. Is it Mono AOT or NativeAOT? Thanks!

@jonathanpeppers jonathanpeppers added the s/needs-info Issue needs more info from the author label Nov 17, 2023
@ghost
Copy link

ghost commented Nov 17, 2023

Hi @Petrarca181. 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.

@Petrarca181
Copy link
Author

Petrarca181 commented Nov 20, 2023

What platform are you targeting here?

2 enable aot

What does this mean? AOT is already enabled in Release mode for mobile, for example.

Unfortunately, just saying "AOT" isn't specific enough. Is it Mono AOT or NativeAOT? Thanks!

Ok now I see, I have two AOT checkboxes. I was speaking about this one .
image

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Nov 20, 2023
@TimLariviere
Copy link
Contributor

TimLariviere commented Nov 21, 2023

I am facing the same issue when trying to enable NativeAOT (via PublishAot = true) for Android target on any .NET MAUI projects, even the default template.

I tried it both on macOS M1 and Windows x64 using dotnet 8.0.100.

To reproduce:

  1. Create a new project from the template
dotnet new maui -n AndroidNativeAotError
  1. Open AndroidNativeAotError.csproj and add the following
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <PublishAot>true</PublishAot>
</PropertyGroup>
  1. Publish the app for Android
dotnet publish -f net8.0-android -c Release /p:AndroidSigningKeyStore=(...) /p:AndroidSigningStorePass=(...) /p:AndroidSigningKeyAlias=(...) /p:AndroidSigningKeyPass=(...) 
  1. dotnet publish should fail with
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
/Users/username/Git/Tests/AndroidNativeAot/AndroidNativeAot.csproj : error NU1101: Unable to find package runtime.linux-arm.Microsoft.DotNet.ILCompiler. No packages exist with this id in source(s): /usr/local/share/dotnet/library-packs, nuget.org
  Failed to restore /Users/username/Git/Tests/AndroidNativeAot/AndroidNativeAot.csproj (in 879 ms).

Note that publishing for net8.0-ios works well.

Full logs for dotnet publish
logs.txt

@TimLariviere
Copy link
Contributor

TimLariviere commented Nov 21, 2023

I checked a little bit the MSBuild logs and noticed the android-arm workload tries to resolve this non-existing runtime.linux-arm.Microsoft.DotNet.ILCompiler.

I thought this was because the RuntimeIdentifier android-arm is buggy, so I switched to <RuntimeIdentifier>android-arm64</RuntimeIdentifier>, but now I get a different error.

MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  AndroidNativeAot -> /Users/username/Git/Tests/AndroidNativeAot/bin/Release/net8.0-android/android-arm64/AndroidNativeAot.dll
/Users/username/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0/build/Microsoft.NETCore.Native.Publish.targets(76,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/Users/username/Git/Tests/AndroidNativeAot/AndroidNativeAot.csproj::TargetFramework=net8.0-android]

Full logs
logs.txt

@Eilon Eilon added the area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging label Nov 21, 2023
@Hooterr
Copy link

Hooterr commented Nov 22, 2023

This seems to be coming from here: https://github.com/dotnet/runtime/blob/e440ebc55895c80fced3410b8018dee79eb2ce4a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets#L74

I got no idea what it does but setting
<PublishAotUsingRuntimePack>true</PublishAotUsingRuntimePack>
gives you
Microsoft.NETCore.Native.Unix.targets(226,5): error : Symbol stripping tool ('llvm-objcopy' or 'objcopy') not found in PATH. Try installing appropriate package for llvm-objcopy or objcopy to resolve the problem or set the StripSymbols property to false to disable symbol stripping.

And then setting
<StripSymbols>false</StripSymbols>
gives you

Unhandled Exception: System.CommandLine.CommandLineException: Target OS 'android' is not supported
     at System.CommandLine.Helpers.GetTargetOS(String) + 0x684
     at System.CommandLine.CliArgument`1.<>c__DisplayClass8_0.<set_CustomParser>b__0(ArgumentResult argumentResult, Object& parsedValue) + 0x44
     at System.CommandLine.Parsing.ArgumentResult.ValidateAndConvert(Boolean) + 0x2ec
     at System.CommandLine.Parsing.CommandResult.ValidateOptions(Boolean) + 0x3cc
     at System.CommandLine.Parsing.CommandResult.Validate(Boolean) + 0x2b4
     at System.CommandLine.Parsing.ParseOperation.Validate() + 0x20
     at System.CommandLine.Parsing.ParseOperation.Parse() + 0x38
     at System.CommandLine.Parsing.CliParser.Parse(CliCommand, IReadOnlyList`1, String, CliConfiguration) + 0x8c
     at System.CommandLine.CliConfiguration.Invoke(String[]) + 0x1c
     at ilc!<BaseAddress>+0x6e6448

Microsoft.NETCore.Native.targets(305,5): error MSB3073: The command ""/Users/mlach/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc" @"obj/Release/net8.0-android/android-arm64/native/FE.Mobile.ilc.rsp"" exited with code 134.

No idea what this all means.

Does the native AOT compilation have any machine type restrictions? Does only work on windows x64 or will it work on any type?
FYI I tried all of the above on an M1 mac.

@Petrarca181
Copy link
Author

For my side, what I found is when you add this to your project: true. It will automatically add Microsoft.DotNet.ILCompiler to your nuget packages. But it can not be resolved bacause runtime.linux-arm (arm32) is not supported anymore.

@jonathanpeppers
Copy link
Member

To be clear, NativeAOT is not yet supported on Android -- that is the cause of the various errors above.

It will be a long road, but the beginning of this work is happening at:

We are just getting started with NativeAOT on Android. It may not even be available when .NET 9 ships, we don't actually know yet.

For now, I would only try to use NativeAOT on iOS, which is also experimental. If you find issues using it, you can file them here:

Hope that helps! But I think we can close this as duplicate of our other ongoing NativeAOT work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants