Search code examples
xamarin.androidmauivisual-studio-2022.net-7.0darwin

Microsoft Android build fails - Could not compile native assembly file


I've created an android project from template in visual studio for mac 2022 (checked supported abi: armebi-v7a)

When i build the projects I randomly get one or more of following errors:

Xamarin.Android.Common.targets(3,3): Error XA3006: Could not compile native assembly file: environment.arm64-v8a.ll

stderr | /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: error: /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: environment.arm64-v8a.ll:554:7: error: expected value token
stderr |                 i32 −1, ; apk_fd

(XA3006) (AndroidApp1)

Xamarin.Android.Common.targets(1979, 3): [XA3006] Could not compile native assembly file: environment.x86.ll
stderr | /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: error: /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: environment.x86.ll:593:7: error: expected value token
stderr |                 i32 −1, ; apk_fd


Xamarin.Android.Common.targets(1979, 3): [XA3006] Could not compile native assembly file: environment.armeabi-v7a.ll
stderr | /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: error: /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: environment.armeabi-v7a.ll:593:7: error: expected value token
stderr |                 i32 −1, ; apk_fd


Xamarin.Android.Common.targets(1979, 3): [XA3006] Could not compile native assembly file: environment.x86_64.ll
stderr | /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: error: /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.26/tools/Darwin/binutils/bin/llc: environment.x86_64.ll:593:7: error: expected value token
stderr |                 i32 −1, ; apk_fd

What can be the problem ? It's working for TargetFramework .net6.0-android

csproj:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net7.0-android33.0.0</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ApplicationId>com.companyname.AndroidApp1</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
    <TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  <AndroidEnableMultiDex>false</AndroidEnableMultiDex>
  <AndroidPackageFormat>apk</AndroidPackageFormat>
</PropertyGroup>

My system:

.NET SDK:
Version:   7.0.202
Commit:    6c74320bc3

Runtime Environment:
OS Name:     Mac OS X
OS Version:  13.2
OS Platform: Darwin
RID:         osx.13-arm64
Base Path:   /usr/local/share/dotnet/sdk/7.0.202/

Host:
 Version:      7.0.4
 Architecture: arm64
 Commit:       0a396acafe

.NET SDKs installed:
 6.0.407 [/usr/local/share/dotnet/sdk]
 7.0.202 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
 Microsoft.AspNetCore.App 6.0.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
 Microsoft.AspNetCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
 Microsoft.NETCore.App 6.0.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
 Microsoft.NETCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
 x64   [/usr/local/share/dotnet/x64]
   registered at [/etc/dotnet/install_location_x64]

Environment variables:
Not set

global.json file:
Not found

EDIT: There is an encoding bug in xamarin for some languages. Description and workaround can be found here: https://github.com/xamarin/xamarin-android/issues/7939


Solution

  • The problem was that on my locale (sv-se) a specific character in .NET Android source code was threated as unicode but should've been threated as ascii. In short words, they forgot to use invariant culture. As a workaround when I got this issue, I changed the os locale to en-US and then it started to work. The fix for this issue was released last year but if it still exists they might forgot to implement the same fix for some other locales. If you read the github link you will see which locale's that got the fix.