dotnet/android

Could not resolve SDK "Microsoft.NET.Runtime.MonoAOTCompiler.Task"

MaximST92 opened this issue · 16 comments

Android framework version

net8.0-android

Affected platform version

.net 8.0.100

Description

Building android application with AOT enabled causes build issues with latest maui-android workload.

[ERR] ---: /Users/runner/.dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.113/targets/Microsoft.Android.Sdk.Aot.targets(25,5): error : Could not resolve SDK "Microsoft.NET.Runtime.MonoAOTCompiler.Task". Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
[ERR] ---: /Users/runner/.dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.113/targets/Microsoft.Android.Sdk.Aot.targets(25,5): error :   SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" returned null.
[ERR] ---: /Users/runner/.dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.113/targets/Microsoft.Android.Sdk.Aot.targets(25,5): error :   The NuGetSdkResolver did not resolve this SDK because there was no version specified in the project or global.json.

Steps to Reproduce

Building existing application was working fine.
Workload update on Azure pipelines caused build to fail.

When using a custom rollback-file workload.json file gives a different error:
[ERR] ---: /Users/runner/.dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.79/targets/Microsoft.Android.Sdk.Aot.targets(109,5): error MSB4044: The "MonoAOTCompiler" task was not given a value for the required parameter "CompilerBinaryPath". [/Users/runner/work/1/s/src/-----] [ERR] ---: /Users/runner/.dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.79/targets/Microsoft.Android.Sdk.Aot.targets(109,5): error MSB4044: The "MonoAOTCompiler" task was not given a value for the required parameter "CompilerBinaryPath". [/Users/runner/work/1/s/src/-----]
(removed project info)

Did you find any workaround?

Workload rollback does not fix the issue, but creates different error.

Relevant log output

No response

workload.json file content:
{ "microsoft.net.sdk.android": "34.0.113/8.0.100", "microsoft.net.workload.mono.toolchain.current": "8.0.6/8.0.100", "microsoft.net.workload.emscripten.current": "8.0.6/8.0.100", "microsoft.net.workload.emscripten.net6": "8.0.6/8.0.100", "microsoft.net.workload.emscripten.net7": "8.0.6/8.0.100", "microsoft.net.workload.mono.toolchain.net6": "8.0.6/8.0.100", "microsoft.net.workload.mono.toolchain.net7": "8.0.6/8.0.100" }

Can you attach a .binlog of the error? https://aka.ms/binlog

If you don't use a rollback file (workload.json) does the problem still occur? Microsoft.NET.Runtime.MonoAOTCompiler.Task is from dotnet/runtime, so the microsoft.net.workload.mono.toolchain.current entry would control what version is used.

Can you attach a .binlog of the error? https://aka.ms/binlog

If you don't use a rollback file (workload.json) does the problem still occur? Microsoft.NET.Runtime.MonoAOTCompiler.Task is from dotnet/runtime, so the microsoft.net.workload.mono.toolchain.current entry would control what version is used.

This is with the latest workloads.
I have created a binlog file, hope this helps.
https://1drv.ms/u/s!AkcCWNpMUZmag91e1Gdgm83XIafawQ?e=CYNpc0

This looks like the installation of dotnet 8.0.300 is corrupt some how?

Warnings: null
Errors: MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.SDK.WorkloadAutoImportPropsLocator" because directory "C:\Program Files\dotnet\sdk\8.0.303\Sdks\Microsoft.NET.SDK.WorkloadAutoImportPropsLocator\Sdk" did not exist

Do you have a global.json in play here?

No, we do not have a global.json file.
This also an issue on our build pipelines on Azure devops.

In your csproj you have the following

<PackageReference Include="Microsoft.NET.Runtime.MonoAOTCompiler.Task" Version="8.0.7" />

I don't think you should be referencing that directly.

That should not be there.
I think it was added when testing the build issue.
Removed, here is a new binlog file.
https://1drv.ms/u/s!AkcCWNpMUZmag91fg78obAoqYgmCpg?e=VQGscR

Out of curiosity does this happen on a vanilla dotnet new android project?

No issue with the vanilla project.
I will compare and step by step try to break the vanilla project.

It can be that it is project related, but we can exclude code change on our side.
We noticed the issue first on a nightly build, so the same code was previously successful.
We have a workload install build step, and there we can see a difference.
The failing build has extra workload manifest installed
Successful build:

14:17:51 [INF] > /usr/local/bin/dotnet workload install maui-android
14:17:51 [DBG]
14:17:53 [DBG] Skipping NuGet package signature verification.
14:17:53 [DBG] Installing workload manifest microsoft.net.sdk.android version 34.0.113...
14:18:02 [DBG] Writing workload pack installation record for Microsoft.Maui.Controls.Core version 8.0.40...
14:18:02 [DBG] Installing pack Microsoft.Maui.Controls.Xaml version 8.0.40...
14:18:03 [DBG] Writing workload pack installation record for Microsoft.Maui.Controls.Xaml version 8.0.40...
14:18:03 [DBG] Installing pack Microsoft.Maui.Controls.Compatibility version 8.0.40...
14:18:03 [DBG] Writing workload pack installation record for Microsoft.Maui.Controls.Compatibility version 8.0.40...
14:18:03 [DBG] Installing pack Microsoft.Maui.Essentials version 8.0.40...
14:18:03 [DBG] Writing workload pack installation record for Microsoft.Maui.Essentials version 8.0.40...
14:18:03 [DBG] Installing pack Microsoft.Android.Sdk.Darwin version 34.0.113...
14:18:14 [DBG] Writing workload pack installation record for Microsoft.Android.Sdk.Darwin version 34.0.113...
14:18:14 [DBG] Installing pack Microsoft.Android.Sdk.Darwin version 33.0.95...
14:18:23 [DBG] Writing workload pack installation record for Microsoft.Android.Sdk.Darwin version 33.0.95...
14:18:23 [DBG] Installing pack Microsoft.Android.Ref.34 version 34.0.113...
14:18:24 [DBG] Writing workload pack installation record for Microsoft.Android.Ref.34 version 34.0.113...
14:18:24 [DBG] Installing pack Microsoft.Android.Runtime.34.android-arm version 34.0.113...
14:18:25 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-arm version 34.0.113...
14:18:25 [DBG] Installing pack Microsoft.Android.Runtime.34.android-arm64 version 34.0.113...
14:18:27 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-arm64 version 34.0.113...
14:18:27 [DBG] Installing pack Microsoft.Android.Runtime.34.android-x86 version 34.0.113...
14:18:28 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-x86 version 34.0.113...
14:18:28 [DBG] Installing pack Microsoft.Android.Runtime.34.android-x64 version 34.0.113...
14:18:30 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-x64 version 34.0.113...
14:18:30 [DBG] Installing pack Microsoft.Android.Templates version 34.0.113...
14:18:30 [DBG] Writing workload pack installation record for Microsoft.Android.Templates version 34.0.113...
14:18:30 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm version 7.0.20...
14:18:32 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm version 7.0.20...
14:18:32 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 7.0.20...
14:18:33 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 7.0.20...
14:18:33 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x64 version 7.0.20...
14:18:38 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x64 version 7.0.20...
14:18:38 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x86 version 7.0.20...
14:18:40 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x86 version 7.0.20...
14:18:40 [DBG] Installing pack Microsoft.NET.Runtime.MonoAOTCompiler.Task version 7.0.20...
14:18:41 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoAOTCompiler.Task version 7.0.20...
14:18:41 [DBG] Installing pack Microsoft.NET.Runtime.MonoTargets.Sdk version 7.0.20...
14:18:41 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoTargets.Sdk version 7.0.20...
14:18:41 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 7.0.20...
14:18:43 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 7.0.20...
14:18:43 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 7.0.20...
14:18:45 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 7.0.20...
14:18:45 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 7.0.20...
14:18:47 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 7.0.20...
14:18:47 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 7.0.20...
14:18:48 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 7.0.20...
14:18:48 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm version 8.0.6...
14:18:49 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm version 8.0.6...
14:18:49 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 8.0.6...
14:18:51 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 8.0.6...
14:18:51 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x64 version 8.0.6...
14:18:53 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x64 version 8.0.6...
14:18:53 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x86 version 8.0.6...
14:18:54 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x86 version 8.0.6...
14:18:54 [DBG] Installing pack Microsoft.NET.Runtime.MonoAOTCompiler.Task version 8.0.6...
14:18:54 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoAOTCompiler.Task version 8.0.6...
14:18:54 [DBG] Installing pack Microsoft.NET.Runtime.MonoTargets.Sdk version 8.0.6...
14:18:55 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoTargets.Sdk version 8.0.6...
14:18:55 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 8.0.6...
14:18:57 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 8.0.6...
14:18:57 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 8.0.6...
14:18:59 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 8.0.6...
14:18:59 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 8.0.6...
14:19:03 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 8.0.6...
14:19:03 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 8.0.6...
14:19:05 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 8.0.6...
14:19:05 [DBG] Garbage collecting for SDK feature band(s) 6.0.400 7.0.100 7.0.200 7.0.300 7.0.400 8.0.100 8.0.200 8.0.300...
14:19:05 [DBG]
14:19:05 [DBG] Successfully installed workload(s) maui-android.
14:19:05 [DBG]

Next the failing build:

06:30:32 [INF] > /usr/local/bin/dotnet workload install maui-android
06:30:33 [DBG]
06:30:34 [DBG] Skipping NuGet package signature verification.
06:30:35 [DBG] Installing workload manifest microsoft.net.sdk.android version 34.0.113...
06:31:00 [DBG] Writing workload pack installation record for Microsoft.Android.Sdk.Darwin version 33.0.95...
06:31:00 [DBG] Installing pack Microsoft.Android.Ref.34 version 34.0.113...
06:31:01 [DBG] Writing workload pack installation record for Microsoft.Android.Ref.34 version 34.0.113...
06:31:01 [DBG] Installing pack Microsoft.Android.Runtime.34.android-arm version 34.0.113...
06:31:02 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-arm version 34.0.113...
06:31:02 [DBG] Installing pack Microsoft.Android.Runtime.34.android-arm64 version 34.0.113...
06:31:04 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-arm64 version 34.0.113...
06:31:04 [DBG] Installing pack Microsoft.Android.Runtime.34.android-x86 version 34.0.113...
06:31:06 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-x86 version 34.0.113...
06:31:06 [DBG] Installing pack Microsoft.Android.Runtime.34.android-x64 version 34.0.113...
06:31:07 [DBG] Writing workload pack installation record for Microsoft.Android.Runtime.34.android-x64 version 34.0.113...
06:31:07 [DBG] Installing pack Microsoft.Android.Templates version 34.0.113...
06:31:07 [DBG] Writing workload pack installation record for Microsoft.Android.Templates version 34.0.113...
06:31:07 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm version 7.0.20...
06:31:09 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm version 7.0.20...
06:31:09 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 7.0.20...
06:31:10 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 7.0.20...
06:31:10 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x64 version 7.0.20...
06:31:12 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x64 version 7.0.20...
06:31:12 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x86 version 7.0.20...
06:31:14 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x86 version 7.0.20...
06:31:14 [DBG] Installing pack Microsoft.NET.Runtime.MonoAOTCompiler.Task version 7.0.20...
06:31:14 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoAOTCompiler.Task version 7.0.20...
06:31:14 [DBG] Installing pack Microsoft.NET.Runtime.MonoTargets.Sdk version 7.0.20...
06:31:14 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoTargets.Sdk version 7.0.20...
06:31:14 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 7.0.20...
06:31:16 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 7.0.20...
06:31:16 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 7.0.20...
06:31:17 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 7.0.20...
06:31:17 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 7.0.20...
06:31:19 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 7.0.20...
06:31:19 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 7.0.20...
06:31:21 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 7.0.20...
06:31:21 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm version 8.0.7...
06:31:23 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm version 8.0.7...
06:31:23 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 8.0.7...
06:31:26 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-arm64 version 8.0.7...
06:31:26 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x64 version 8.0.7...
06:31:28 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x64 version 8.0.7...
06:31:28 [DBG] Installing pack Microsoft.NETCore.App.Runtime.Mono.android-x86 version 8.0.7...
06:31:29 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.android-x86 version 8.0.7...
06:31:29 [DBG] Installing pack Microsoft.NET.Runtime.MonoAOTCompiler.Task version 8.0.7...
06:31:29 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoAOTCompiler.Task version 8.0.7...
06:31:29 [DBG] Installing pack Microsoft.NET.Runtime.MonoTargets.Sdk version 8.0.7...
06:31:30 [DBG] Writing workload pack installation record for Microsoft.NET.Runtime.MonoTargets.Sdk version 8.0.7...
06:31:30 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 8.0.7...
06:31:32 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x86 version 8.0.7...
06:31:32 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 8.0.7...
06:31:35 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-x64 version 8.0.7...
06:31:35 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 8.0.7...
06:31:40 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm version 8.0.7...
06:31:40 [DBG] Installing pack Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 8.0.7...
06:31:44 [DBG] Writing workload pack installation record for Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.android-arm64 version 8.0.7...
06:31:44 [DBG] Garbage collecting for SDK feature band(s) 6.0.400 7.0.100 7.0.200 7.0.300 7.0.400 8.0.100 8.0.200 8.0.300...
06:31:44 [DBG]
06:31:44 [DBG] Successfully installed workload(s) maui-android.
06:31:44 [DBG]

Adding this to the vanilla project causes it to fail:
<AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>

@jonathanpeppers should people be using AndroidEnableProfiledAot instead of just using standard Aot?

I checked the docs.
https://learn.microsoft.com/en-us/dotnet/maui/migration/android-projects?view=net-maui-8.0#ahead-of-time-compilation
I noticed that in our project, the RunAOTCompilation flag was missing.
So the combination
<RunAOTCompilation>true</RunAOTCompilation> <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
Fixes the issue.
Not sure why this suddenly was an issue, but it was missing on our side.

<RunAOTCompilation>true</RunAOTCompilation> <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>

These are the default values for Release mode:

<!-- Default to AOT in Release mode -->
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == '' and '$(Configuration)' == 'Release' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == 'true' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' ">false</RunAOTCompilation>
<_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true</_AndroidXA1029>
<_AndroidXA1030 Condition=" '$(RunAOTCompilation)' == 'true' and '$(PublishTrimmed)' == 'false' ">true</_AndroidXA1030>
<AotAssemblies>$(RunAOTCompilation)</AotAssemblies>
<AndroidEnableProfiledAot Condition=" '$(AndroidEnableProfiledAot)' == '' and '$(RunAOTCompilation)' == 'true' and '$(AndroidStripILAfterAOT)' != 'true' ">true</AndroidEnableProfiledAot>

Why do you need to set these at all? Is your $(Configuration) named something other than Release?

Yes, we have multiple configurations for different environments.
We do not have a default release config.

I would not recommend using multiple $(Configuration) names like this, see:

Since there are N potentially unknown properties you would need to set, no one know the exhaustive list of properties to set to get it right. I bet you don't have $(Optimize), set for example, which is fairly important for performance.

If you need to set something for different environments, I would simply use a different property other than $(Configuration) like:

-p:MySetting=Production

And then use Condition against your $(MySetting) property instead of $(Configuration).