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

Can't build .NET 7 android projects #7939

Closed
mrhenkiz opened this issue Apr 6, 2023 · 25 comments · Fixed by #7941
Closed

Can't build .NET 7 android projects #7939

mrhenkiz opened this issue Apr 6, 2023 · 25 comments · Fixed by #7941
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@mrhenkiz
Copy link

mrhenkiz commented Apr 6, 2023

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 2022 17.5.3, .NET SDK 7.0.200, osx.13-arm64, Mono 6.12.0.188

Description

Can't build .NET 7.0 android project, newly created from template in visual studio. If i change to .net6.0-android however, it will build.

Csproj:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net7.0-android</TargetFramework> <SupportedOSPlatformVersion>23</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>

My system:

.NET SDK:
Version: 7.0.202
Commit: 6c74320bc3

Runtime Environment:
OS Name: Mac OS X
OS Version: 13.3
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

Workloads:

Installed Workload Id Manifest Version Installation Source

wasm-tools 7.0.4/7.0.100 SDK 7.0.200
macos 13.1.1040/7.0.100 SDK 7.0.200
maui-maccatalyst 7.0.59/7.0.100 SDK 7.0.200
maui-ios 7.0.59/7.0.100 SDK 7.0.200
maui-android 7.0.59/7.0.100 SDK 7.0.200
tvos 16.1.1537/7.0.100 SDK 7.0.200
android 33.0.26/7.0.100 SDK 7.0.200

Steps to Reproduce

  • Install android workload
  • Create .NET android project from visual studio template
    • Build solution (either via visual studio or command line)

Did you find any workaround?

No

Relevant log output

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
@mrhenkiz mrhenkiz added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Apr 6, 2023
@dellis1972
Copy link
Contributor

@grendello any ideas on this one?

@dellis1972 dellis1972 removed the needs-triage Issues that need to be assigned. label Apr 6, 2023
@grendello
Copy link
Contributor

This code is generated when assembly stores are disabled ($(AndroidUseAssemblyStore)=False), but I've just tested it locally and it builds fine with XA/main. @mrhenkiz can you please attach the whole project directory after build (that is with bin, obj, sources etc)?

@grendello
Copy link
Contributor

Fragment of code generated locally when assembly stores are disabled:

; Bundled assembly name buffers, all 70 bytes long
@bundled_assemblies = local_unnamed_addr global [154 x %struct.XamarinAndroidBundledAssembly] [
        ; 0
        %struct.XamarinAndroidBundledAssembly {
                i32 -1, ; apk_fd
                i32 0, ; data_offset
                i32 0, ; data_size
                i8* null, ; data
                i32 70, ; name_length
                i8* getelementptr inbounds ([70 x i8], [70 x i8]* @__XamarinAndroidBundledAssembly_name_0, i32 0, i32 0); name
        }, 

It's an array of such entries, the fragment in the error message in OP isn't sufficient to say what llc doesn't like.

@mrhenkiz
Copy link
Author

mrhenkiz commented Apr 6, 2023

@grendello Thanks for the quick response. The zipfile is 26mb and I'm only allowed to upload 25mb. Is there any folders that i can skip to make the file smaller ?

EDIT: Uploaded it to file.io
Link

@grendello
Copy link
Contributor

I can confirm that the ll files in the provided sample fail to build, even though the code between my local test and them is nearly identical (the only difference is buffer size):

Local:

; Bundled assembly name buffers, all 70 bytes long
@bundled_assemblies = local_unnamed_addr global [154 x %struct.XamarinAndroidBundledAssembly] [
        ; 0
        %struct.XamarinAndroidBundledAssembly {
                i32 -1, ; apk_fd
                i32 0, ; data_offset
                i32 0, ; data_size
                i8* null, ; data
                i32 70, ; name_length
                i8* getelementptr inbounds ([70 x i8], [70 x i8]* @__XamarinAndroidBundledAssembly_name_0, i32 0, i32 0); name
        }, 

Example app:

; Bundled assembly name buffers, all 66 bytes long
@bundled_assemblies = local_unnamed_addr global [211 x %struct.XamarinAndroidBundledAssembly] [
        ; 0
        %struct.XamarinAndroidBundledAssembly {
                i32 −1, ; apk_fd
                i32 0, ; data_offset
                i32 0, ; data_size
                i8* null, ; data
                i32 66, ; name_length
                i8* getelementptr inbounds ([66 x i8], [66 x i8]* @__XamarinAndroidBundledAssembly_name_0, i32 0, i32 0); name
        }, 

Syntactically they're identical, so it must be something else in the file throwing llc off. Fascinating.

@grendello
Copy link
Contributor

If I manually change -1 to 0 then it works. Baffling :)

@mrhenkiz
Copy link
Author

mrhenkiz commented Apr 6, 2023

@grendello I don't know if it helps. But the errors for environment is randomly between every build. Sometimes it only complains about ie. environment.arm64-v8a.ll and other builds it complains about one or more. :)

@grendello
Copy link
Contributor

@mrhenkiz I suspect there's some earlier bit of code that is somehow corrupted (perhaps a filesystem issue, hard to tell). I'll investigate later today and will try to reproduce locally using your sample.

@mrhenkiz
Copy link
Author

mrhenkiz commented Apr 6, 2023

@grendello Great, thanks. I can also say that i get same errors on a wiped intel mac where I only installed vs 2022 17.5.3 and created a project from the template (same versions as on the M1) and built.

@rhult
Copy link

rhult commented Apr 6, 2023

FWIW, I also get this same error consistently on two different projects when trying to build with .net7.0-android, and it works with .net6.0-android (on an M2 mac).

@grendello
Copy link
Contributor

OK, I know what happens, but no idea why yet. So, consider these two entries from the same array:

        ; 3
        %struct.XamarinAndroidBundledAssembly {
                i32 -1, ; apk_fd
                i32 0, ; data_offset
                i32 0, ; data_size
                i8* null, ; data
                i32 66, ; name_length
                i8* getelementptr inbounds ([66 x i8], [66 x i8]* @__XamarinAndroidBundledAssembly_name_3, i32 0, i32 0); name
        }, 
        ; 4
        %struct.XamarinAndroidBundledAssembly {
                i32 −1, ; apk_fd
                i32 0, ; data_offset
                i32 0, ; data_size
                i8* null, ; data
                i32 66, ; name_length
                i8* getelementptr inbounds ([66 x i8], [66 x i8]* @__XamarinAndroidBundledAssembly_name_4, i32 0, i32 0); name
        }, 

The first one works, the 2nd one doesn't. And you would be forgiven if you don't spot the difference, because it depends on your display font :). The problem is the - character which in the 2nd -1 is not ASCII 0x2D (dec 45) but rather Unicode 0x2212 (dec 8722) which can be found in this PDF on page 2, 3rd row and 2nd column.

Since the integer is output to the file with ye olde ToString (), it must be a matter of the locale/encoding on the machine that generates the code (possibly also .NET version?). I was able to build the sample on Linux (with net8) and on macOS (with net7), with both machines using the en_US.UTF-8 locale.

@mrhenkiz @rhult what are your locales on the machines you see the error occur?

@grendello
Copy link
Contributor

For context: dotnet/runtime#13363

@rhult
Copy link

rhult commented Apr 6, 2023

I'm using sv_SE.UTF-8 on macOS.

@grendello
Copy link
Contributor

@rhult precisely the encoding that causes the problem then. We have the answer, now off to fix it :) The fix is simple, but you might want to work around the problem by using LANG=en_SE.UTF-8 when compiling in the meantime.

@mrhenkiz
Copy link
Author

mrhenkiz commented Apr 6, 2023

Thanks for quick response @grendello. @rhult Did you confirm that it's working if you change LANG ? Where to change the lang in macos?

@grendello
Copy link
Contributor

FYI, these cultures also use the same minus sign and will be affected by this bug:

et
et-EE
eu
eu-ES
fi
fi-FI
fo
fo-DK
fo-FO
gsw
gsw-CH
gsw-FR
gsw-LI
hr
hr-BA
hr-HR
ksh
ksh-DE
lt
lt-LT
nb
nb-NO
nb-SJ
nn
nn-NO
no
rm
rm-CH
se
se-FI
se-NO
se-SE
sl
sl-SI
sv
sv-AX
sv-FI
sv-SE

@grendello
Copy link
Contributor

Thanks for quick response @grendello. @rhult Did you confirm that it's working if you change LANG ? Where to change the lang in macos?

If you build from command line, you can just do:

$ LANG=en_US.UTF-8 dotnet build [...]

@grendello
Copy link
Contributor

@mrhenkiz you can put

export LANG=en_US.UTF-8

in the .profile file in your home directory, then that value of LANG will be used for all terminal sessions. For GUI apps you'd either have to use the defaults utility (from terminal, do defaults read | less to see all the settings) or change the language in the macOS settings app.

@mrhenkiz
Copy link
Author

mrhenkiz commented Apr 6, 2023

@grendello Thank you. It worked like a charm when I added it to .zshrc :) Great job!

grendello added a commit to grendello/xamarin-android that referenced this issue Apr 6, 2023
Fixes: dotnet#7939
Context: dotnet/runtime#13363
Context: https://www.unicode.org/charts/PDF/U2200.pdf (page 2)

LLVM IR generator outputs a number of integer values, relying on the
standard `ToString()` method to convert the value to string.  However,
since NET6, this conversion is culture-sensitive and in certain
cultures (list below) it will output the minus sign not as the standard
ASCII 0x2D character but rather as the Unicode 0x2212 (mathematical
operator "minus") character.  This breaks LLVM LLC:

    llc: environment.arm64-v8a.ll:554:7: error: expected value token
      stderr |                 i32 −1, ; apk_fd

Fix the problem by using invariant culture when converting **all**
integers and unknown objects to strings.  The reason all of them are
converted in this way is to avoid future changes to ICU and/or .NET
to-string conversion that might affect the resulting integer format.

Locales/cultures affected by this issue are as follows:

  * et
  * et-EE
  * eu
  * eu-ES
  * fi
  * fi-FI
  * fo
  * fo-DK
  * fo-FO
  * gsw
  * gsw-CH
  * gsw-FR
  * gsw-LI
  * hr
  * hr-BA
  * hr-HR
  * ksh
  * ksh-DE
  * lt
  * lt-LT
  * nb
  * nb-NO
  * nb-SJ
  * nn
  * nn-NO
  * no
  * rm
  * rm-CH
  * se
  * se-FI
  * se-NO
  * se-SE
  * sl
  * sl-SI
  * sv
  * sv-AX
  * sv-FI
  * sv-SE
@PRMrainbow
Copy link

How can I change LANG in Windows?

@mrhenkiz
Copy link
Author

@PRMrainbow
Copy link

I have same error after changing system language from zh-TW to en-US.

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\Xamarin.Android.Common.targets(1979,3): error XA3006: Could not compile native assembly file: typemaps.arm64-v8a.ll

@grendello
Copy link
Contributor

@PRMrainbow are you absolutely sure it's the same error? The zh-TW culture appears to use the ASCII hyphen as the minus character. Can you build your app from command line with:

dotnet build -c Release -bl
dotnet msbuild -v:diag msbuild.binlog > msbuild.txt

and then locate the string error XA3006: in msbuild.txt to see what the actual error is (it will be somewhere above the error line, might be mixed up with other lines if parallel build is in effect)

@PRMrainbow
Copy link

Well... It was built successfully with 'dotnet build -c Release -bl' while building in Visual Studio IDE it failed. So I can't get an error in msbuild.txt.

@grendello
Copy link
Contributor

@PRMrainbow then it's unlikely to be the same issue. However, maybe you'll get more info if you enable diagnostic MSBuild messages inside the IDE and hunt for the error in the output buffer after the build fails there.

jonpryor pushed a commit that referenced this issue Apr 17, 2023
Fixes: #7939

Context: dotnet/runtime#13363
Context: https://www.unicode.org/charts/PDF/U2200.pdf (page 2)
Context: 5271f3e

The LLVM IR generator (5271f3e) outputs a number of integer values,
relying on the standard `int.ToString()` method to convert the value
to a string.  However, since .NET 6, this conversion is culture-
sensitive and in certain cultures (list below) it will output the
minus sign not as the "standard" ASCII \u002d character `-` but
instead as something else (see complete list below for details).

This breaks LLVM LLC:

	llc: environment.arm64-v8a.ll:554:7: error: expected value token
	  stderr |                 i32 −1, ; apk_fd

Fix the problem by using invariant culture when converting ***all***
integers and unknown objects to strings.  The reason all of them are
converted in this way is to avoid future changes to ICU and/or .NET
to-string conversion that might affect the resulting integer format.

Workaround: export `$LANG` to a locale that uses 0x2D `-` for
negation, e.g. `LANG=C`.

Locales/cultures affected by this issue are as follows:

  * ARABIC LETTER MARK + HYPHEN-MINUS `؜-` (\u061c \u002d): 26 cultures
    * ar
    * ar-001
    * ar-BH
    * ar-DJ
    * ar-EG
    * ar-ER
    * ar-IL
    * ar-IQ
    * ar-JO
    * ar-KM
    * ar-KW
    * ar-LB
    * ar-MR
    * ar-OM
    * ar-PS
    * ar-QA
    * ar-SA
    * ar-SD
    * ar-SO
    * ar-SS
    * ar-SY
    * ar-TD
    * ar-YE
    * sd
    * sd-Arab
    * sd-Arab-PK
  * LEFT-TO-RIGHT MARK + HYPHEN-MINUS `‎-` (\u200e \u002d): 10 cultures
    * ar-AE
    * ar-DZ
    * ar-EH
    * ar-LY
    * ar-MA
    * ar-TN
    * he
    * he-IL
    * ur
    * ur-PK
  * RIGHT-TO-LEFT MARK + HYPHEN-MINUS `‏-` (\u200f \u002d): 3 cultures
    * ckb
    * ckb-IQ
    * ckb-IR
  * MINUS SIGN `−` (\u2212): 38 cultures
    * et
    * et-EE
    * eu
    * eu-ES
    * fi
    * fi-FI
    * fo
    * fo-DK
    * fo-FO
    * gsw
    * gsw-CH
    * gsw-FR
    * gsw-LI
    * hr
    * hr-BA
    * hr-HR
    * ksh
    * ksh-DE
    * lt
    * lt-LT
    * nb
    * nb-NO
    * nb-SJ
    * nn
    * nn-NO
    * no
    * rm
    * rm-CH
    * se
    * se-FI
    * se-NO
    * se-SE
    * sl
    * sl-SI
    * sv
    * sv-AX
    * sv-FI
    * sv-SE
  * LEFT-TO-RIGHT MARK + MINUS SIGN `‎−` (\u200e \u2212): 3 cultures
    * fa
    * fa-AF
    * fa-IR
  * LEFT-TO-RIGHT MARK + HYPHEN-MINUS + LEFT-TO-RIGHT MARK `‎-‎` (\u200e \u002d \u002e): 16 cultures
    * ks
    * ks-Arab
    * ks-Arab-IN
    * lrc
    * lrc-IQ
    * lrc-IR
    * mzn
    * mzn-IR
    * pa-Arab
    * pa-Arab-PK
    * ps
    * ps-AF
    * ps-PK
    * ur-IN
    * uz-Arab
    * uz-Arab-AF

Update `BuildTest2.BuildBasicApplication()` to export
`LANG=sv_SE.UTF-8` as part of the `dotnet build` command to test this
scenario on macOS and Linux.  (This change is ignored on Windows.)
jonathanpeppers pushed a commit that referenced this issue Apr 25, 2023
Fixes: #7939

Context: dotnet/runtime#13363
Context: https://www.unicode.org/charts/PDF/U2200.pdf (page 2)
Context: 5271f3e

The LLVM IR generator (5271f3e) outputs a number of integer values,
relying on the standard `int.ToString()` method to convert the value
to a string.  However, since .NET 6, this conversion is culture-
sensitive and in certain cultures (list below) it will output the
minus sign not as the "standard" ASCII \u002d character `-` but
instead as something else (see complete list below for details).

This breaks LLVM LLC:

	llc: environment.arm64-v8a.ll:554:7: error: expected value token
	  stderr |                 i32 −1, ; apk_fd

Fix the problem by using invariant culture when converting ***all***
integers and unknown objects to strings.  The reason all of them are
converted in this way is to avoid future changes to ICU and/or .NET
to-string conversion that might affect the resulting integer format.

Workaround: export `$LANG` to a locale that uses 0x2D `-` for
negation, e.g. `LANG=C`.

Locales/cultures affected by this issue are as follows:

  * ARABIC LETTER MARK + HYPHEN-MINUS `؜-` (\u061c \u002d): 26 cultures
    * ar
    * ar-001
    * ar-BH
    * ar-DJ
    * ar-EG
    * ar-ER
    * ar-IL
    * ar-IQ
    * ar-JO
    * ar-KM
    * ar-KW
    * ar-LB
    * ar-MR
    * ar-OM
    * ar-PS
    * ar-QA
    * ar-SA
    * ar-SD
    * ar-SO
    * ar-SS
    * ar-SY
    * ar-TD
    * ar-YE
    * sd
    * sd-Arab
    * sd-Arab-PK
  * LEFT-TO-RIGHT MARK + HYPHEN-MINUS `‎-` (\u200e \u002d): 10 cultures
    * ar-AE
    * ar-DZ
    * ar-EH
    * ar-LY
    * ar-MA
    * ar-TN
    * he
    * he-IL
    * ur
    * ur-PK
  * RIGHT-TO-LEFT MARK + HYPHEN-MINUS `‏-` (\u200f \u002d): 3 cultures
    * ckb
    * ckb-IQ
    * ckb-IR
  * MINUS SIGN `−` (\u2212): 38 cultures
    * et
    * et-EE
    * eu
    * eu-ES
    * fi
    * fi-FI
    * fo
    * fo-DK
    * fo-FO
    * gsw
    * gsw-CH
    * gsw-FR
    * gsw-LI
    * hr
    * hr-BA
    * hr-HR
    * ksh
    * ksh-DE
    * lt
    * lt-LT
    * nb
    * nb-NO
    * nb-SJ
    * nn
    * nn-NO
    * no
    * rm
    * rm-CH
    * se
    * se-FI
    * se-NO
    * se-SE
    * sl
    * sl-SI
    * sv
    * sv-AX
    * sv-FI
    * sv-SE
  * LEFT-TO-RIGHT MARK + MINUS SIGN `‎−` (\u200e \u2212): 3 cultures
    * fa
    * fa-AF
    * fa-IR
  * LEFT-TO-RIGHT MARK + HYPHEN-MINUS + LEFT-TO-RIGHT MARK `‎-‎` (\u200e \u002d \u002e): 16 cultures
    * ks
    * ks-Arab
    * ks-Arab-IN
    * lrc
    * lrc-IQ
    * lrc-IR
    * mzn
    * mzn-IR
    * pa-Arab
    * pa-Arab-PK
    * ps
    * ps-AF
    * ps-PK
    * ur-IN
    * uz-Arab
    * uz-Arab-AF

Update `BuildTest2.BuildBasicApplication()` to export
`LANG=sv_SE.UTF-8` as part of the `dotnet build` command to test this
scenario on macOS and Linux.  (This change is ignored on Windows.)
@ghost ghost locked as resolved and limited conversation to collaborators May 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants