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

Could not AOT the Assemblies - Visual Studio 16.10 #5964

Closed
EP01 opened this issue May 27, 2021 · 12 comments · Fixed by #5979
Closed

Could not AOT the Assemblies - Visual Studio 16.10 #5964

EP01 opened this issue May 27, 2021 · 12 comments · Fixed by #5979
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@EP01
Copy link

EP01 commented May 27, 2021

Steps to Reproduce

  1. Update to VS 16.10.0.
  2. Try to archive a Xamarin Android app with AOT + LLVM enabled. I used the default Xamarin Forms template to reproduce easily by just changing those two parameters in Release config and pressing Archive. I've attached this.
  3. Fails

App2.zip

@EP01 EP01 added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels May 27, 2021
@dellis1972
Copy link
Contributor

This looks like a duplicate of #5764

@dellis1972 dellis1972 added duplicate and removed needs-triage Issues that need to be assigned. labels May 27, 2021
@EP01
Copy link
Author

EP01 commented May 27, 2021

Sorry @dellis1972, I missed that because it was raised in March, I assumed it would have been amongst the more recent issues.

@dellis1972
Copy link
Contributor

@EP01 no problem :D

@inforithmics
Copy link

inforithmics commented May 31, 2021

@dellis1972 Can you reopen this issue. Because #5764 is a different issue.

I discovered that llvm with Visual Studio 2019 16.10 doesn't work.
The reason is that the Android sdk path has a space and then the ndk doesn't work see comments in the other issue.

#5764 (comment)

Works:
C:\Users\[username]\AppData\Local\Android\sdk
Doesn't work:
C:\program Files (x86)\Android\android-sdk

And altough azure devops builds start failing because of this.

@AndreyBespamyatnov
Copy link

The same issue for AzureDevOps builds:

2021-05-31T21:49:31.2416389Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
2021-05-31T21:49:31.2417574Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-31T21:49:31.2419262Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk\21.4.7075529\platforms\android-21\arch-arm\usr\lib: No such file or directory

@dellis1972 dellis1972 reopened this Jun 1, 2021
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jun 1, 2021
Fixes dotnet#5964

We missed a few paths which might need to be quoted in order to handle
spaces in the paths.

```
2021-05-28T22:15:09.3191452Z   [aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
2021-05-28T22:15:09.3195848Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3197593Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
2021-05-28T22:15:09.3199375Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3200935Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
2021-05-28T22:15:09.3202549Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3204244Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
2021-05-28T22:15:09.3205865Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
2021-05-28T22:15:09.3207138Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
2021-05-28T22:15:09.3208785Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
2021-05-28T22:15:09.3210086Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl
```

So lets quote ALL the things.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jun 2, 2021
Fixes dotnet#5964

We missed a few paths which might need to be quoted in order to handle
spaces in the paths.

```
2021-05-28T22:15:09.3191452Z   [aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
2021-05-28T22:15:09.3195848Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3197593Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
2021-05-28T22:15:09.3199375Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3200935Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
2021-05-28T22:15:09.3202549Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3204244Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
2021-05-28T22:15:09.3205865Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
2021-05-28T22:15:09.3207138Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
2021-05-28T22:15:09.3208785Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
2021-05-28T22:15:09.3210086Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl
```

So lets quote ALL the things.
@VictorKochetkov
Copy link

The same issue for AzureDevOps builds:

2021-05-31T21:49:31.2416389Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
2021-05-31T21:49:31.2417574Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-31T21:49:31.2419262Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk\21.4.7075529\platforms\android-21\arch-arm\usr\lib: No such file or directory

Same issue on home PC and on Github actions

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jun 2, 2021
Fixes dotnet#5964

We missed a few paths which might need to be quoted in order to handle
spaces in the paths.

```
2021-05-28T22:15:09.3191452Z   [aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
2021-05-28T22:15:09.3195848Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3197593Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
2021-05-28T22:15:09.3199375Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3200935Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
2021-05-28T22:15:09.3202549Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3204244Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
2021-05-28T22:15:09.3205865Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
2021-05-28T22:15:09.3207138Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
2021-05-28T22:15:09.3208785Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
2021-05-28T22:15:09.3210086Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl
```

So lets quote ALL the things.
@jonpryor
Copy link
Member

jonpryor commented Jun 2, 2021

@AndreyBespamyatnov or @VictorKochetkov : would either of you be able to provide a complete .binlog file, or a diagnostic build log, for when your build fails?

I'm confused, because the GitHub Actions Microsoft Windows Server 2019 Datacenter Image states that the Android NDK is installed under C:\Android\android-sdk, a directory that contains no spaces. I thus wonder how $(AndroidSdkDirectory) is being detected in a manner which causes it to find an NDK path which is not documented on GitHub Actions.

jonpryor pushed a commit that referenced this issue Jun 2, 2021
Fixes: #5964

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1336413

Context: accc846
Context: 8923c11
Context: 9b928f9

Customers report that when building a project:

 1. On Windows
 2. With Visual Studio 16.10, *not* 16.9 or earlier
 3. In Release configuration
 4. With `$(AotAssemblies)`=True *and* `$(EnableLLVM)`=True
 5. With the NDK installed into a directory containing spaces

then the app fails to build:

	[aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl

The *immediate* cause of the failure is path quoting: the
`arm-linux-androideabi-ld.EXE` invocation contains:

	-LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x 

This value is not quoted, and parts of that path are seen in the
error messages:

	error: cannot open Files: No such file or directory
	error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory

"So", we say, "let's quote those paths!"

Update the `<Aot/>` task so that *all* the paths passed to Mono in the
`ld-flags` parameter are quoted, not just `libgcc.a`, `libc.so`, and
`libm.so`.  This fixes the above linker invocation.

Additionally, update the `AotTests` test fixture so that when the
tests run on Windows, Android SDK and NDK installation locations are
symlinked into a directory containing spaces and Ümläüts.
These "SDK Ümläüts" directories are then used by the unit tests.
This helps *ensure* that we're appropriately wrapping paths, by
ensuring that the SDK & NDK are in a directory with spaces.

We don't (yet) use these "SDK Ümläüts" for macOS unit tests because
the Android NDK `aarch64-linux-android21-clang` & related scripts
don't properly quote paths either:

	`dirname $0`/clang --target=aarch64-linux-android21 "$@"

which means an `SDK Ümläüts/ndk/…/aarch64-linux-android21-clang`
invocation fails with:

	usage: dirname path

TODO: address this shortcoming, by skipping
`aarch64-linux-android21-clang` and instead directly executing
`…/clang --target=aarch64-linux-android21`.

---

…except.  Except.

Except a lot of this doesn't *quite* make sense.

Lack of path quoting, *in and of itself*, is readily explainable and
plainly observed here.

The problem is that `ld-flags` construction hasn't changed much since
commit 8923c11, in 2019-Sep-4 (21 months ago!), in particular the
`libs.Add($"-L{toolchainLibDir}")` and
`libs.Add($"-L{androidLibPath}")` statements.  Commit 9b928f9
changed this slightly, wrapping `libgcc.a`/etc. with quotes, but did
*not* touch `toolchainLibDir` or `androidLibPath`, both of which are
responsible for the `-L…` values implicated in the above errors.

Thus, we are getting customer complaints related to AOT path quoting
when none of the relevant code has changed between d16-9 and d16-10.
The only AOT-related change is accc846, which added support to pass
the new-to-mono `ld-name` option for AOT.  `ld-name` *doesn't*
involve the directory name, and thus doesn't seem relevant here.

We *know* `ld-flags` is *involved*, because updating the `ld-flags`
value we provide to mono fixes the issue.  However, is this a
*fix* or a *workaround*? ¯\_(ツ)_/¯ 

Additionally, *why* did this start failing with d16-10?

  * Xamarin.Android change that isn't "obviously" related to AOT?

  * Mono changes?
    mono/mono@5e9cb6d...b4a3858

    There are no "obvious" changes in behavior related to `ld-flags`
    or `ld_flags`, nor anything else "obvious" that would alter
    behavior.

  * "Environment" change, e.g. in d16-9 the NDK was installed into a
    directory that lacked spaces, while in d16-10 the NDK is now
    installed into a directory containing spaces?

    There *may* be something here, but it's hard to say.
    The [GitHub Actions Microsoft Windows Server 2019 Datacenter][0]
    environment lists the NDK installation location as a path with
    *no* spaces:

        C:\Android\android-sdk\ndk\22.1.7171670

    Yet we have a report of the same "path quoting" failure happening
    ["on Github actions"][1], referencing a path that differs from
    the documented path:

        C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x

    Why does the documentation mention `C:\Android`, while
    `C:\Program Files (x86)` is used?

    Did our NDK path lookup logic change?

We don't currently know why things started blowing up in
Visual Studio 16.10.  Investigation is ongoing.

[0]: https://github.com/actions/virtual-environments/blob/2823a3cb6a62cc74961527bdf7623b4b9afb4107/images/win/Windows2019-Readme.md
[1]: #5964 (comment)
jonpryor pushed a commit that referenced this issue Jun 2, 2021
Fixes: #5964

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1336413

Context: accc846
Context: 8923c11
Context: 9b928f9

Customers report that when building a project:

 1. On Windows
 2. With Visual Studio 16.10, *not* 16.9 or earlier
 3. In Release configuration
 4. With `$(AotAssemblies)`=True *and* `$(EnableLLVM)`=True
 5. With the NDK installed into a directory containing spaces

then the app fails to build:

	[aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl

The *immediate* cause of the failure is path quoting: the
`arm-linux-androideabi-ld.EXE` invocation contains:

	-LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x 

This value is not quoted, and parts of that path are seen in the
error messages:

	error: cannot open Files: No such file or directory
	error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory

"So", we say, "let's quote those paths!"

Update the `<Aot/>` task so that *all* the paths passed to Mono in the
`ld-flags` parameter are quoted, not just `libgcc.a`, `libc.so`, and
`libm.so`.  This fixes the above linker invocation.

Additionally, update the `AotTests` test fixture so that when the
tests run on Windows, Android SDK and NDK installation locations are
symlinked into a directory containing spaces and Ümläüts.
These "SDK Ümläüts" directories are then used by the unit tests.
This helps *ensure* that we're appropriately wrapping paths, by
ensuring that the SDK & NDK are in a directory with spaces.

We don't (yet) use these "SDK Ümläüts" for macOS unit tests because
the Android NDK `aarch64-linux-android21-clang` & related scripts
don't properly quote paths either:

	`dirname $0`/clang --target=aarch64-linux-android21 "$@"

which means an `SDK Ümläüts/ndk/…/aarch64-linux-android21-clang`
invocation fails with:

	usage: dirname path

TODO: address this shortcoming, by skipping
`aarch64-linux-android21-clang` and instead directly executing
`…/clang --target=aarch64-linux-android21`.

---

…except.  Except.

Except a lot of this doesn't *quite* make sense.

Lack of path quoting, *in and of itself*, is readily explainable and
plainly observed here.

The problem is that `ld-flags` construction hasn't changed much since
commit 8923c11, in 2019-Sep-4 (21 months ago!), in particular the
`libs.Add($"-L{toolchainLibDir}")` and
`libs.Add($"-L{androidLibPath}")` statements.  Commit 9b928f9
changed this slightly, wrapping `libgcc.a`/etc. with quotes, but did
*not* touch `toolchainLibDir` or `androidLibPath`, both of which are
responsible for the `-L…` values implicated in the above errors.

Thus, we are getting customer complaints related to AOT path quoting
when none of the relevant code has changed between d16-9 and d16-10.
The only AOT-related change is accc846, which added support to pass
the new-to-mono `ld-name` option for AOT.  `ld-name` *doesn't*
involve the directory name, and thus doesn't seem relevant here.

We *know* `ld-flags` is *involved*, because updating the `ld-flags`
value we provide to mono fixes the issue.  However, is this a
*fix* or a *workaround*? ¯\_(ツ)_/¯ 

Additionally, *why* did this start failing with d16-10?

  * Xamarin.Android change that isn't "obviously" related to AOT?

  * Mono changes?
    mono/mono@5e9cb6d...b4a3858

    There are no "obvious" changes in behavior related to `ld-flags`
    or `ld_flags`, nor anything else "obvious" that would alter
    behavior.

  * "Environment" change, e.g. in d16-9 the NDK was installed into a
    directory that lacked spaces, while in d16-10 the NDK is now
    installed into a directory containing spaces?

    There *may* be something here, but it's hard to say.
    The [GitHub Actions Microsoft Windows Server 2019 Datacenter][0]
    environment lists the NDK installation location as a path with
    *no* spaces:

        C:\Android\android-sdk\ndk\22.1.7171670

    Yet we have a report of the same "path quoting" failure happening
    ["on Github actions"][1], referencing a path that differs from
    the documented path:

        C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x

    Why does the documentation mention `C:\Android`, while
    `C:\Program Files (x86)` is used?

    Did our NDK path lookup logic change?

We don't currently know why things started blowing up in
Visual Studio 16.10.  Investigation is ongoing.

[0]: https://github.com/actions/virtual-environments/blob/2823a3cb6a62cc74961527bdf7623b4b9afb4107/images/win/Windows2019-Readme.md
[1]: #5964 (comment)
jonpryor pushed a commit that referenced this issue Jun 3, 2021
Fixes: #5964

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1336413

Context: accc846
Context: 8923c11
Context: 9b928f9

Customers report that when building a project:

 1. On Windows
 2. With Visual Studio 16.10, *not* 16.9 or earlier
 3. In Release configuration
 4. With `$(AotAssemblies)`=True *and* `$(EnableLLVM)`=True
 5. With the NDK installed into a directory containing spaces

then the app fails to build:

	[aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
	[aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl

The *immediate* cause of the failure is path quoting: the
`arm-linux-androideabi-ld.EXE` invocation contains:

	-LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x 

This value is not quoted, and parts of that path are seen in the
error messages:

	error: cannot open Files: No such file or directory
	error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory

"So", we say, "let's quote those paths!"

Update the `<Aot/>` task so that *all* the paths passed to Mono in the
`ld-flags` parameter are quoted, not just `libgcc.a`, `libc.so`, and
`libm.so`.  This fixes the above linker invocation.

Additionally, update the `AotTests` test fixture so that when the
tests run on Windows, Android SDK and NDK installation locations are
symlinked into a directory containing spaces and Ümläüts.
These "SDK Ümläüts" directories are then used by the unit tests.
This helps *ensure* that we're appropriately wrapping paths, by
ensuring that the SDK & NDK are in a directory with spaces.

We don't (yet) use these "SDK Ümläüts" for macOS unit tests because
the Android NDK `aarch64-linux-android21-clang` & related scripts
don't properly quote paths either:

	`dirname $0`/clang --target=aarch64-linux-android21 "$@"

which means an `SDK Ümläüts/ndk/…/aarch64-linux-android21-clang`
invocation fails with:

	usage: dirname path

TODO: address this shortcoming, by skipping
`aarch64-linux-android21-clang` and instead directly executing
`…/clang --target=aarch64-linux-android21`.

---

…except.  Except.

Except a lot of this doesn't *quite* make sense.

Lack of path quoting, *in and of itself*, is readily explainable and
plainly observed here.

The problem is that `ld-flags` construction hasn't changed much since
commit 8923c11, in 2019-Sep-4 (21 months ago!), in particular the
`libs.Add($"-L{toolchainLibDir}")` and
`libs.Add($"-L{androidLibPath}")` statements.  Commit 9b928f9
changed this slightly, wrapping `libgcc.a`/etc. with quotes, but did
*not* touch `toolchainLibDir` or `androidLibPath`, both of which are
responsible for the `-L…` values implicated in the above errors.

Thus, we are getting customer complaints related to AOT path quoting
when none of the relevant code has changed between d16-9 and d16-10.
The only AOT-related change is accc846, which added support to pass
the new-to-mono `ld-name` option for AOT.  `ld-name` *doesn't*
involve the directory name, and thus doesn't seem relevant here.

We *know* `ld-flags` is *involved*, because updating the `ld-flags`
value we provide to mono fixes the issue.  However, is this a
*fix* or a *workaround*? ¯\_(ツ)_/¯ 

Additionally, *why* did this start failing with d16-10?

  * Xamarin.Android change that isn't "obviously" related to AOT?

  * Mono changes?
    mono/mono@5e9cb6d...b4a3858

    There are no "obvious" changes in behavior related to `ld-flags`
    or `ld_flags`, nor anything else "obvious" that would alter
    behavior.

  * "Environment" change, e.g. in d16-9 the NDK was installed into a
    directory that lacked spaces, while in d16-10 the NDK is now
    installed into a directory containing spaces?

    There *may* be something here, but it's hard to say.
    The [GitHub Actions Microsoft Windows Server 2019 Datacenter][0]
    environment lists the NDK installation location as a path with
    *no* spaces:

        C:\Android\android-sdk\ndk\22.1.7171670

    Yet we have a report of the same "path quoting" failure happening
    ["on Github actions"][1], referencing a path that differs from
    the documented path:

        C:\Program Files (x86)\Android\android-sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x

    Why does the documentation mention `C:\Android`, while
    `C:\Program Files (x86)` is used?

    Did our NDK path lookup logic change?

We don't currently know why things started blowing up in
Visual Studio 16.10.  Investigation is ongoing.

[0]: https://github.com/actions/virtual-environments/blob/2823a3cb6a62cc74961527bdf7623b4b9afb4107/images/win/Windows2019-Readme.md
[1]: #5964 (comment)
@jonpryor
Copy link
Member

jonpryor commented Jun 3, 2021

While trying to investigate what's going on…

d16-10 install with the following files from 16-9: cross-*.exe:

  • Fails; suggests it's not (just?) the mono bump.

d16-10 install with the following files from d16-9: opt.exe, llc.exe:

  • Fails; suggests it's not due to any LLVM bumps part of the mono bump.

d16-10 install with the following files from d16-9: Xamarin.Android.Aapt2.targets, Xamarin.Android.Build.Tasks.dll, Xamarin.Android.Common.targets, Xamarin.Android.Legacy.targets, Java.Interop.Tools.JavaCallableWrappers.dll

  • Works!

Which implies a xamarin-android change.

The change to Java.Interop.Tools.JavaCallableWrappers.dll doesn't seem plausible in the context of AOT.

This also allows us to ask a related question: Why isn't the path quoting in commit 6a5df16 needed? How did this work in d16-9? (I could install d16-9, but now that I have a "Frankenstein" build environment…)

The answer? -LC: does not appear in the build log, and it was the presence of -LC:\Path With Spaces\… in the ld-flags value created by the <Aot/> task and passed into mono which caused the problem. ld-flags only contains the (quoted!) paths to libgcc.a, libc.so, and libm.so.

This explains why the lack of quotes around toolchainLibDir and androidLibPath wasn't previously a problem; they weren't previously used:

https://github.com/xamarin/xamarin-android/blob/d7282f4385146469958cc922d99138553d653fe8/src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs#L360-L369

They weren't previously used because, by inference, NdkUtil.UsingClangNDK was false. Now it's (presumably) true, which causes the -LC:\… paths to be used, which broke the world.

This allows us to focus on NdkUtil.UsingClangNDK semantics and possible changes…

@jonpryor
Copy link
Member

jonpryor commented Jun 4, 2021

Now we start getting to where I can't as easily provide URLs for diffs…

What changed in NdkUtils.cs?

git diff origin/d16-9...origin/d16-10 src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs

Nothing directly related to the UsingClangNDK property or usingClangNDK field, which means we're left with the original logic:

https://github.com/xamarin/xamarin-android/blob/0e5e06f716c7e9044e66ed27b75fcd722c546127/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs#L44

NdkUtils.UsingClangNDK is true if the NDK version is >= 19.

And indeed, if I install an NDK r18 release, d16-10 is able to build with $(AotAssemblies)=True and $(EnableLLVM)=True! (Yay?)

However, my frankenstein environment was able to build with an NDK >= 19. Why?

Commit accc846 isn't present in d16-9, is present in d16-10, and has an important change:

accc846#diff-d4dcca33896738b8e073a8fde94253a72f9b76cf0923179cb06a94a8db740f41R234

		public async override System.Threading.Tasks.Task RunTaskAsync ()
		{
			// NdkUtil must always be initialized - once per thread
			if (!NdkUtil.Init (LogCodedError, AndroidNdkDirectory)) {
				LogDebugMessage ("Failed to initialize NdkUtil");
				return;
			}

d16-9 has the same method override, but lacks the NdkUtil.Init() invocation.

NdkUtil.Init() is what sets NdkUtil.UsingClangNDK, which is backed by a thread-local value:

https://github.com/xamarin/xamarin-android/blob/0e5e06f716c7e9044e66ed27b75fcd722c546127/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs#L21-L23

Additionally, RunTaskAsync() is always run on a new thread:

https://github.com/xamarin/xamarin-android-tools/blob/81519fe22ec00320a4f340f4d20d415848a1b16e/src/Microsoft.Android.Build.BaseTasks/AndroidAsyncTask.cs#L28-L41

Consequently, on d16-9, NdkUtil.UsingClangNDK is always false. Thus, it never executes the libs.Add($"-L{toolchainLibDir}") statement which was responsible for the -LC:\Path With Spaces\… entry within ld-flags.

d16-10 does appropriately call NdkUtil.Init(), which ensures that the NdkUtil.usingClangNDK thread-local value is properly set for all threads, which in turn means NdkUtil.UsingClangNDK will be true…if/when the NDK is > r19, which is almost certainly the case.

The reason it never broke before d16-10 is because we never properly set the info needed to know we were on a newer NDK until d16-10!

@queequac
Copy link

queequac commented Jun 11, 2021

Is a fix coming with the next update of VS 16.10? I am currently blocked and cannot archive apps... unfortunately switching over to a path without spaces does not work as a workarround for me, it still fails due to the same error.

And still wondering why the path in the error message has a line break and a missing character at the position where the concatenation takes places:

[aot-compiler stderr] C:\short\Android\android-sdk
dk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory

grendello added a commit to grendello/xamarin-android that referenced this issue Jul 14, 2021
Context: dotnet#5996
Context: dotnet#5964
Context: dotnet#5964 (comment)

The `NdkUtils` class used by Xamarin.Andrid.Build.Tasks to find tooling
shipped with the Android NDK, has grown increasingly complicated over
the years due to a number of incompatibilities between various versions
of the NDK. The code became hard to follow and untidy. This commit
attempts to address the issue by replacing the single static `NdkUtils`
class with a hierarchy of dynamically instantiated classes rooted in a
new base class, `NdkTools`.

`NdkUtils` had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
`NdkUtils` was first accessed, meaning that any task using it had to do
it.

`NdkTools` doesn't require such initialization, instead it provides a
factory method called `Create` which takes path to the NDK as its
parameter and returns an instance of `NdkTools` child class (or `null`
if an error occurs) which the can be safely used by the caller.  Callers
need not concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
`NdkTools` base abstract class.

The hierarchy of `NdkTools` derivatives is structured and named after
the breaking changes in the NDK.  For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
`NdkTools`, `NoClang` for NDKs older than r16 and `WithClang` for the
newer ones. The other breaking changes are the addition of unified
headers in r19, removal of the `platforms` directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported. Support
for r23 is being worked on in PR dotnet#6073 which will be merged once r23 is
out of beta.
grendello added a commit to grendello/xamarin-android that referenced this issue Jul 14, 2021
Context: dotnet#5996
Context: dotnet#5964
Context: dotnet#5964 (comment)

The `NdkUtils` class used by Xamarin.Andrid.Build.Tasks to find tooling
shipped with the Android NDK, has grown increasingly complicated over
the years due to a number of incompatibilities between various versions
of the NDK. The code became hard to follow and untidy. This commit
attempts to address the issue by replacing the single static `NdkUtils`
class with a hierarchy of dynamically instantiated classes rooted in a
new base class, `NdkTools`.

`NdkUtils` had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
`NdkUtils` was first accessed, meaning that any task using it had to do
it.

`NdkTools` doesn't require such initialization, instead it provides a
factory method called `Create` which takes path to the NDK as its
parameter and returns an instance of `NdkTools` child class (or `null`
if an error occurs) which the can be safely used by the caller.  Callers
need not concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
`NdkTools` base abstract class.

The hierarchy of `NdkTools` derivatives is structured and named after
the breaking changes in the NDK.  For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
`NdkTools`, `NoClang` for NDKs older than r16 and `WithClang` for the
newer ones. The other breaking changes are the addition of unified
headers in r19, removal of the `platforms` directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported. Support
for r23 is being worked on in PR dotnet#6073 which will be merged once r23 is
out of beta.
grendello added a commit to grendello/xamarin-android that referenced this issue Jul 14, 2021
Context: dotnet#5996
Context: dotnet#5964
Context: dotnet#5964 (comment)

The `NdkUtils` class used by Xamarin.Andrid.Build.Tasks to find tooling
shipped with the Android NDK, has grown increasingly complicated over
the years due to a number of incompatibilities between various versions
of the NDK. The code became hard to follow and untidy. This commit
attempts to address the issue by replacing the single static `NdkUtils`
class with a hierarchy of dynamically instantiated classes rooted in a
new base class, `NdkTools`.

`NdkUtils` had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
`NdkUtils` was first accessed, meaning that any task using it had to do
it.

`NdkTools` doesn't require such initialization, instead it provides a
factory method called `Create` which takes path to the NDK as its
parameter and returns an instance of `NdkTools` child class (or `null`
if an error occurs) which the can be safely used by the caller.  Callers
need not concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
`NdkTools` base abstract class.

The hierarchy of `NdkTools` derivatives is structured and named after
the breaking changes in the NDK.  For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
`NdkTools`, `NoClang` for NDKs older than r16 and `WithClang` for the
newer ones. The other breaking changes are the addition of unified
headers in r19, removal of the `platforms` directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported. Support
for r23 is being worked on in PR dotnet#6073 which will be merged once r23 is
out of beta.
grendello added a commit to grendello/xamarin-android that referenced this issue Jul 14, 2021
Context: dotnet#5996
Context: dotnet#5964
Context: dotnet#5964 (comment)

The `NdkUtils` class used by Xamarin.Andrid.Build.Tasks to find tooling
shipped with the Android NDK, has grown increasingly complicated over
the years due to a number of incompatibilities between various versions
of the NDK. The code became hard to follow and untidy. This commit
attempts to address the issue by replacing the single static `NdkUtils`
class with a hierarchy of dynamically instantiated classes rooted in a
new base class, `NdkTools`.

`NdkUtils` had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
`NdkUtils` was first accessed, meaning that any task using it had to do
it.

`NdkTools` doesn't require such initialization, instead it provides a
factory method called `Create` which takes path to the NDK as its
parameter and returns an instance of `NdkTools` child class (or `null`
if an error occurs) which the can be safely used by the caller.  Callers
need not concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
`NdkTools` base abstract class.

The hierarchy of `NdkTools` derivatives is structured and named after
the breaking changes in the NDK.  For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
`NdkTools`, `NoClang` for NDKs older than r16 and `WithClang` for the
newer ones. The other breaking changes are the addition of unified
headers in r19, removal of the `platforms` directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported. Support
for r23 is being worked on in PR dotnet#6073 which will be merged once r23 is
out of beta.
jonpryor pushed a commit that referenced this issue Jul 15, 2021
Context: #5964
Context: #5964 (comment)
Context: #5996
Context: #6073

The `NdkUtils` class is used by Xamarin.Andrid.Build.Tasks to find
tooling shipped with the Android NDK, and has grown increasingly
complicated over the years due to a number of incompatibilities
between various NDK versions. The code became hard to follow and
untidy.

Address this issue by replacing the single static `NdkUtils` class
with a hierarchy of dynamically instantiated classes rooted in a new
base class, `NdkTools`.

`NdkUtils` had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
`NdkUtils` was first accessed, meaning that every task using it had to
do it; see accc846 & [this comment][0].

`NdkTools` doesn't require such initialization, instead it provides an
`NdkTools.Create()` factory method takes the path to the NDK and
returns an instance of an `NdkTools` subclass (or `null` if an error
occurs), which the can be safely used by the caller.  Callers need not
concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
`NdkTools` base abstract class.

The hierarchy of `NdkTools` derivatives is structured and named after
the breaking changes in the NDK.  For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
`NdkTools`, `NoClang` for NDKs older than r16 and `WithClang` for the
newer ones.  The other breaking changes are the addition of unified
headers in r19, removal of the `platforms` directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported.
Support for r23 is being worked on in PR #6073, which will be merged
once r23 is out of beta.

[0]: #5964 (comment)
@Tommigun1980
Copy link

@jonpryor I'm using Visual Studio for Mac 8.10.6 and this is still broken. Did the fix not land in the latest version? If not, when will it be released? It would be nice being able to make release builds again.

Thank you.

@jonathanpeppers
Copy link
Member

@Tommigun1980 I believe this fix is only available in VS Windows 16.11, there isn't an equivalent release for VS Mac yet.

Can you try this build and see if it solves your issue, thanks!

https://dl.internalx.com/vsts-devdiv/Xamarin.Android/public/4941337/d16-11/7776c9f1c8fac303c3aa57867825990850be0384/xamarin.android-11.4.0.5.pkg

@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2022
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.

9 participants