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

XARRA7028 AssemblyResolutionException in Android App Release Build #9629

Open
uholeschak opened this issue Dec 18, 2024 · 2 comments
Open

XARRA7028 AssemblyResolutionException in Android App Release Build #9629

uholeschak opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review

Comments

@uholeschak
Copy link

uholeschak commented Dec 18, 2024

Android framework version

net9.0-android

Affected platform version

VS2022 17.12.3

Description

When building and publishing an Android app in Release mode the build always fails with the following error message, but the missing System.Private.CoreLib Version=9.0.0.0 is present.
The problem is the MSBuild target _RemoveRegisterAttribute, which is run after AOT. Is seems that in this state the assembly dependencies are not accessible any more.

XARRA7028: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

Steps to Reproduce

  1. Create and build an Android NET9 app in release mode with the default settings:
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <AndroidLinkTool>r8</AndroidLinkTool>
    <AndroidEnableMultiDex>True</AndroidEnableMultiDex>
  1. Publish the app to the target. In this step the error occurs.

Did you find any workaround?

Disable the _RemoveRegisterAttribute target by setting in Directory.Build.Props:

<Project>
  <Target Name="PatchRemoveRegisterAttributeBefore" BeforeTargets="_RemoveRegisterAttribute">
    <PropertyGroup>
      <AndroidIncludeDebugSymbolsStd>$(AndroidIncludeDebugSymbols)</AndroidIncludeDebugSymbolsStd>
      <AndroidIncludeDebugSymbols Condition=" '$(EmbedAssembliesIntoApk)' == 'True' ">True</AndroidIncludeDebugSymbols>
    </PropertyGroup>
  </Target>
  <Target Name="PatchRemoveRegisterAttributeAfter" AfterTargets="_RemoveRegisterAttribute">
    <PropertyGroup>
      <AndroidIncludeDebugSymbols Condition=" '$(EmbedAssembliesIntoApk)' == 'True' ">$(AndroidIncludeDebugSymbolsStd)</AndroidIncludeDebugSymbols>
    </PropertyGroup>
  </Target>
</Project>

Relevant log output

XARRA7028: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
   bei Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   bei Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   bei Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   bei Mono.Cecil.TypeReference.Resolve()
   bei Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   bei Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
   bei Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
   bei Mono.Cecil.MetadataBuilder.AddField(FieldDefinition field)
   bei Mono.Cecil.MetadataBuilder.AddFields(TypeDefinition type)
   bei Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   bei Mono.Cecil.MetadataBuilder.AddTypes()
   bei Mono.Cecil.MetadataBuilder.BuildTypes()
   bei Mono.Cecil.MetadataBuilder.BuildModule()
   bei Mono.Cecil.MetadataBuilder.BuildMetadata()
   bei Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
   bei Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   bei Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   bei Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   bei Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
   bei Xamarin.Android.Tasks.RemoveRegisterAttribute.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAttribute.cs:Zeile 33.
   bei Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:Zeile 25.
@uholeschak uholeschak added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Dec 18, 2024
@jonathanpeppers
Copy link
Member

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

You should be able to remove $(AndroidEnableMultiDex) completely as both d8 and r8 automatically do this for you.

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels Dec 18, 2024
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Dec 18, 2024
@uholeschak
Copy link
Author

I have created the logs when execution the publish operation in VS (when the error occurs).
The complete build logs before are not included to reduce the size.
MSBuildReproLogs.zip

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review
Projects
None yet
Development

No branches or pull requests

3 participants