Avalonia源代码编译的一些总结

编译遇到的错误

初次编译Avalonia源码也许会遇到很多各种各样的问题。有一些问题根据错误提示能够比较容易的解决。但还有一些问题,根据错误提示也不太容易推测出来如何解决。在这里记录一下我遇到的一些问题,供遇到类似问题的朋友参考。

Namespace could not be found

bash 复制代码
megatron@localhost:~/SourceCode/Avalonia$ ./build.sh --target Compile --configuration Release
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Microsoft (R) .NET SDK version 7.0.404
/home/megatron/SourceCode/Avalonia/nukebuild/BuildTasksPatcher.cs(5,7): error CS0246: The type or namespace name 'ILRepacking' could not be found (are you missing a using directive or an assembly reference?) [/home/megatron/SourceCode/Avalonia/nukebuild/_build.csproj]
/home/megatron/SourceCode/Avalonia/nukebuild/Shims.cs(8,7): error CS0246: The type or namespace name 'Numerge' could not be found (are you missing a using directive or an assembly reference?) [/home/megatron/SourceCode/Avalonia/nukebuild/_build.csproj]
/home/megatron/SourceCode/Avalonia/nukebuild/Shims.cs(96,31): error CS0246: The type or namespace name 'INumergeLogger' could not be found (are you missing a using directive or an assembly reference?) [/home/megatron/SourceCode/Avalonia/nukebuild/_build.csproj]
/home/megatron/SourceCode/Avalonia/nukebuild/Shims.cs(98,25): error CS0246: The type or namespace name 'NumergeLogLevel' could not be found (are you missing a using directive or an assembly reference?) [/home/megatron/SourceCode/Avalonia/nukebuild/_build.csproj]

这是因为clone Avalonia代码库后,没有拉取submodule导致的。使用git submodule update --init拉取submodule后重新编译源码即可。

File being used by another process

ruby 复制代码
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018: System.IO.IOException: The process cannot access the file '/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/bin/Release/netstandard2.0/DevAnalyzers.deps.json' because it is being used by another process. [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Init(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Int64& fileLength, UnixFileMode& filePermissions) [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func`4 createOpenException) [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at System.IO.File.Create(String path) [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath) [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]
[ERR] Compile: /home/megatron/dotnet/sdk/7.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(211,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/megatron/SourceCode/Avalonia/src/tools/DevAnalyzers/DevAnalyzers.csproj]

使用fuser查看DevAnalyzers.deps.json并没有被别的进程使用。怀疑是并行编译导致的问题,不作任何修改,重新执行编译发现问题消失了。

The Android SDK directory could not be found

vbnet 复制代码
[ERR] Compile: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.95\tools\Xamarin.Android.Tooling.targets(70,5): error XA5300: The Android SDK directory could not be found. Install the Android SDK by following the instructions at: https://aka.ms/dotnet-android-install-sdk [C:\Users\megatron\SourceCode\Avalonia\src\Android\Avalonia.Android\Avalonia.Android.csproj]
[ERR] Compile: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.95\tools\Xamarin.Android.Tooling.targets(70,5): error XA5300: To use a custom SDK path for a command line build, set the 'AndroidSdkDirectory' MSBuild property to the custom path. [C:\Users\megatron\SourceCode\Avalonia\src\Android\Avalonia.Android\Avalonia.Android.csproj]
[ERR] Compile: Target Compile has thrown an exception

这是在Windows平台编译Avalonia时遇到的问题。机器确实安装了Android SDK但还是报错。推测由于Android SDK安装到了一个编译脚本无法检测到的位置导致的。把Android SDK的安装路径移动到C:\Program files(x86)\Android\android-sdk后问题得到了解决。

The Java SDK directory could not be found

vbnet 复制代码
[ERR] Compile: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.95\tools\Xamarin.Android.Tooling.targets(70,5): error XA5300: The Java SDK directory could not be found. Install the Java SDK by following the instructions at: https://aka.ms/dotnet-android-install-sdk [C:\Users\megatron\SourceCode\Avalonia\src\Android\Avalonia.Android\Avalonia.Android.csproj]
[ERR] Compile: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.95\tools\Xamarin.Android.Tooling.targets(70,5): error XA5300: To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MSBuild property to the custom path. [C:\Users\megatron\SourceCode\Avalonia\src\Android\Avalonia.Android\Avalonia.Android.csproj]
[ERR] Compile: Target Compile has thrown an exception

learn.microsoft.com/en-us/java/... 下载了微软的OpenJDK安装后问题得到解决。

执行workload-install安装Tizen workload无效

这是在安装Tizen workload时遇到的问题。执行workload-install时立即结束,没有任何错误提示,但看起来什么也没有发生,去dotnet workload的目录会发现Tizen workload并没有完成安装。使用strace分析了一下workload-install的执行过程,发现是dotnet命令无法被workload-install脚本导致的。使用export DOTNET_ROOT=/home/megatron/dotnet设置DOTNET_ROOT环境变量后,workload-install脚本就能正常执行了。

源码编译得到的nupkg

以下nupkg在Windows/Linux/macOS都能够编译出来的nupkg。

Package Name
Avalonia
Avalonia.Browser
Avalonia.Browser.Blazor
Avalonia.Controls.ColorPicker
Avalonia.Controls.DataGrid
Avalonia.Controls.ItemsRepeater
Avalonia.Desktop
Avalonia.Diagnostics
Avalonia.Direct2D1
Avalonia.Fonts.Inter
Avalonia.FreeDesktop
Avalonia.Headless
Avalonia.Headless.NUnit
Avalonia.Headless.Vnc
Avalonia.Headless.XUnit
Avalonia.LinuxFramebuffer
Avalonia.Markup.Xaml.Loader
Avalonia.ReactiveUI
Avalonia.Remote.Protocol
Avalonia.Skia
Avalonia.Themes.Fluent
Avalonia.Themes.Simple
Avalonia.Win32
Avalonia.X11

还有几个nupkg只能在特定平台编译得到。

Package Name Windows Linux macOS
Avalonia.Andriod Yes No No
Avalonia.iOS Yes No No
Avalonia.Win32.Interoperability Yes No No
Avalonia.Native No No Yes

可以看到如果想要通过编译得到所有的Avalonia nupkg,那么需要至少准备Windows和macOS两台机器来做编译。这里有个我还不太明白的地方:官方编译还需要Linux机器,既然Windows和macOS能编译出Avalonia所有的nupkg,那为什么还要再额外找一台Linux机器做编译呢?

相关推荐
也无晴也无风雨1 小时前
深入剖析输入URL按下回车,浏览器做了什么
前端·后端·计算机网络
Martin -Tang2 小时前
Vue 3 中,ref 和 reactive的区别
前端·javascript·vue.js
FakeOccupational4 小时前
nodejs 020: React语法规则 props和state
前端·javascript·react.js
放逐者-保持本心,方可放逐4 小时前
react 组件应用
开发语言·前端·javascript·react.js·前端框架
曹天骄5 小时前
next中服务端组件共享接口数据
前端·javascript·react.js
阮少年、5 小时前
java后台生成模拟聊天截图并返回给前端
java·开发语言·前端
郝晨妤6 小时前
鸿蒙ArkTS和TS有什么区别?
前端·javascript·typescript·鸿蒙
AvatarGiser7 小时前
《ElementPlus 与 ElementUI 差异集合》Icon 图标 More 差异说明
前端·vue.js·elementui
喝旺仔la7 小时前
vue的样式知识点
前端·javascript·vue.js
别忘了微笑_cuicui7 小时前
elementUI中2个日期组件实现开始时间、结束时间(禁用日期面板、控制开始时间不能超过结束时间的时分秒)实现方案
前端·javascript·elementui