Mac 部署 UE 开发环境

MacOS 安装 UE

UE 要求 MacOS 的分区格式为 不区分大小写 (不然 EpicLauncher 也无法安装),而且安装引擎的要求是系统版本大于10.13.5,否则会出现引擎崩溃和一些不支持的情况(尝试忽略错误无法安装成功)。
编译依赖 xcode,就像依赖 VS 一样,需要安装编译环境。
如果安装完 UE 和 Xcode 之后创建项目提示下列错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
An error occurred while trying to generate project files.
Running Mono...
Setting up Mono
/Users/Shared/UnrealEngine/4.22/Engine /Users/Shared/UnrealEngine/4.22/Engine/Binaries/Mac
Discovering modules, targets and source code for project...
Compiling with non-standard Xcode (xcode-select): /Library/Developer/CommandLineTools/
Triggered an exception while looking for SDK directory in Xcode.app
System.IO.DirectoryNotFoundException: Directory '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs' not found.
at System.IO.Directory.ValidateDirectoryListing (System.String path, System.String searchPattern, System.Boolean& stop) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetDirectories (System.String path, System.String searchPattern) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetDirectories (System.String path) [0x00000] in <filename unknown>:0
at UnrealBuildTool.AppleToolChain.SelectSDK (System.String BaseSDKDir, System.String OSPrefix, System.String& PlatformSDKVersion, Boolean bVerbose) [0x00000] in <filename unknown>:0
ERROR: Invalid SDK MacOSX.sdk, not found in /Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs

则安装Xcode Command Line Tools,然后执行以下命令即可:

1
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms /Library/Developer/CommandLineTools/

Mac 修改 SSHD 默认端口

有些内网有端口限制,低于 xxxx 的端口默认不开放,所以在 22 端口被限制的情况下如何进行远程构建?修改 SSH 的默认端口!

编辑 /etc/services 文件中的 ssh 的端口:

1
$ vim /etc/services

把 SSH 的端口改为其他的:

1
2
ssh              22/udp     # SSH Remote Login Protocol
ssh 22/tcp # SSH Remote Login Protocol

修改为:

1
2
ssh              2222/udp     # SSH Remote Login Protocol
ssh 2222/tcp # SSH Remote Login Protocol

保存退出。
还需要重新加载配置使端口生效:

1
2
$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

然后测试端口是否可以连接:

1
$ ssh localhost -p 2222

为 xcode 开启多线程编译

首先看一下 Mac 的硬件配置:

1
$ sysctl machdep.cpu

找到 machdep.cpu.core_count 字段,其中的数值就是 Mac 的核心数。

然后可以给 xcode 开启多线程,数量数为核心数 *2,如我的是 8 核,就可以开启 16 线程:

1
$ defaults write com.apple.Xcode PBXNumberOfParallelBuildSubtasks 16

Mac 系统内置的 Framework

有时候需要在 UE 的模块中引入系统的 Framework,那么 Mac 默认包含哪些 Framework 呢?可以通过以下方式查看。
我使用的系统版本为 10.15.2,可以通过sw_vers 查看:

1
2
3
4
[email protected] ~ % sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.2
BuildVersion: 19C57

系统内置的 Framework 在以下目录中:

1
/System/Library/Frameworks

10.15.2 版本中包含以下 framework:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
AGL.framework                           ColorSync.framework                     CoreVideo.framework                    GameKit.framework
LinkPresentation.framework OpenGL.framework SoundAnalysis.framework
AVFoundation.framework Combine.framework CoreWLAN.framework GameplayKit.framework
LocalAuthentication.framework PCSC.framework Speech.framework
AVKit.framework Contacts.framework CryptoKit.framework HIDDriverKit.framework
MapKit.framework PDFKit.framework SpriteKit.framework
Accelerate.framework ContactsUI.framework CryptoTokenKit.framework Hypervisor.framework
MediaAccessibility.framework PencilKit.framework StoreKit.framework
Accounts.framework CoreAudio.framework DVDPlayback.framework ICADevices.framework
MediaLibrary.framework Photos.framework SwiftUI.framework
AdSupport.framework CoreAudioKit.framework DeviceCheck.framework IMServicePlugIn.framework
MediaPlayer.framework PhotosUI.framework SyncServices.framework
AddressBook.framework CoreAudioTypes.framework DirectoryService.framework IOBluetooth.framework
MediaToolbox.framework PreferencePanes.framework System.framework
AppKit.framework CoreBluetooth.framework DiscRecording.framework IOBluetoothUI.framework
Message.framework PushKit.framework SystemConfiguration.framework
AppleScriptKit.framework CoreData.framework DiscRecordingUI.framework IOKit.framework
Metal.framework Python.framework SystemExtensions.framework
AppleScriptObjC.framework CoreDisplay.framework DiskArbitration.framework IOSurface.framework
MetalKit.framework QTKit.framework TWAIN.framework
ApplicationServices.framework CoreFoundation.framework DriverKit.framework IOUSBHost.framework
MetalPerformanceShaders.framework Quartz.framework Tcl.framework
AudioToolbox.framework CoreGraphics.framework EventKit.framework IdentityLookup.framework
MetricKit.framework QuartzCore.framework Tk.framework
AudioUnit.framework CoreHaptics.framework ExceptionHandling.framework ImageCaptureCore.framework
ModelIO.framework QuickLook.framework USBDriverKit.framework
AudioVideoBridging.framework CoreImage.framework ExecutionPolicy.framework ImageIO.framework
MultipeerConnectivity.framework QuickLookThumbnailing.framework UserNotifications.framework
AuthenticationServices.framework CoreLocation.framework ExternalAccessory.framework InputMethodKit.framework
NaturalLanguage.framework RealityKit.framework VideoDecodeAcceleration.framework
Automator.framework CoreMIDI.framework FWAUserLib.framework InstallerPlugins.framework
NetFS.framework Ruby.framework VideoSubscriberAccount.framework
BackgroundTasks.framework CoreMIDIServer.framework FileProvider.framework InstantMessage.framework
Network.framework SafariServices.framework VideoToolbox.framework
BusinessChat.framework CoreML.framework FileProviderUI.framework Intents.framework
NetworkExtension.framework SceneKit.framework Vision.framework
CFNetwork.framework CoreMedia.framework FinderSync.framework JavaFrameEmbedding.framework
NetworkingDriverKit.framework ScreenSaver.framework WebKit.framework
CalendarStore.framework CoreMediaIO.framework ForceFeedback.framework JavaScriptCore.framework
NotificationCenter.framework ScriptingBridge.framework iTunesLibrary.framework
CallKit.framework CoreMotion.framework Foundation.framework JavaVM.framework
OSAKit.framework Security.framework vecLib.framework
Carbon.framework CoreServices.framework GLKit.framework Kerberos.framework
OSLog.framework SecurityFoundation.framework vmnet.framework
CloudKit.framework CoreSpotlight.framework GLUT.framework Kernel.framework
OpenAL.framework SecurityInterface.framework
Cocoa.framework CoreTelephony.framework GSS.framework LDAP.framework
OpenCL.framework ServiceManagement.framework
Collaboration.framework CoreText.framework GameController.framework LatentSemanticMapping.framework
OpenDirectory.framework Social.framework

安装 CommandLineTool

Xcode’s metal shader compiler was not found, verify Xcode has been installed on this Mac and that it has been selected in Xcode > Preferences > Locations > Command-line Tools.

相关问题:

离线安装 XCodeCommand Line Tools for Xcode可以从苹果的开发者网站下载:More Downloads for Apple Developers

在安装完 Command Line Tools 之后,如果 cook 时还是提示这个错误,则需要执行下列命令 (当然要首先确保/Library/Developer/CommandLineTools 路径存在,一般 Command Line Tools 的默认安装路径是这个):

1
$ sudo xcode-select -s /Library/Developer/CommandLineTools

当设置 CommandLineTools 之后打包时可能会提示:

1
ERROR: Invalid SDK MacOSX.sdk, not found in /Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs

这是因为通过 xcode-select 设置为 CommandLineTools 之后,打包时找不到 Xcode 里的库了。
解决的办法是在 CommandLineTools 的目录下创建一个 Xcode 中的 Platforms 目录的软连接:

1
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms /Library/Developer/CommandLineTools/Platforms

actool 错误

1
2
UATHelper: Packaging (iOS):   xcrun: error: unable to find utility "actool", not a developer tool or in PATH
PackagingResults: Error: unable to find utility "actool", not a developer tool or in PATH

这是因为把 CommandLinTool 设置为默认的命令行工具之后,CommandLinTool/use/bin下并没有 actool 等工具。
这是个十分坑爹的问题,用 xcode 作为默认的命令行工具导致 Cook 不过,用 CommandLineTool 又在编译时有问题。
我的解办法是把 /Applications/Xcode.app/Contents/Developer/usr/bin 通过软连接方式链接到/Library/Developer/CommandLineTools/usr:

1
2
3
4
# 当然要先备份 CommandLineTool/usr/bin
$ mv /Library/Developer/CommandLineTools/usr/bin /Library/Developer/CommandLineTools/usr/Command_bin
# 创建 xcode 的 bin 目录的软连接
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin /Library/Developer/CommandLineTools/usr/bin

解除 MacOS 安装软件的限制

  • 允许任何来源,运行第三方应用
1
sudo spctl --master-disable
  • 安装灰色的 dmg
1
hdiutil attach #dmg 文件名 #

MacOS 读写 NTFS

装上 macOS 之后发现,macOS 可以读取 ntfs 的文件,但是不可以写入,这十分蛋疼。
查了一下说是因为微软的限制,但是 macOS 本身是做了读写的功能的,只是被关闭了,可以通过以下方法开启。

首先,在终端下执行 diskutil list 查看磁盘信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
visionsmile$ diskutil list
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *240.1 GB disk0
1: EFI 312.5 MB disk0s1
2: Microsoft Reserved 134.2 MB disk0s2
3: Microsoft Basic Data Windows 164.3 GB disk0s3
4: Apple_APFS Container disk1 75.3 GB disk0s4

/dev/disk1 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +75.3 GB disk1
Physical Store disk0s4
1: APFS Volume OSX 34.2 GB disk1s1
2: APFS Volume Preboot 21.1 MB disk1s2
3: APFS Volume Recovery 509.8 MB disk1s3
4: APFS Volume VM 2.1 GB disk1s4

/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *4.0 TB disk2
1: Microsoft Reserved 134.2 MB disk2s1
2: Microsoft Basic Data Document 4.0 TB disk2s2

/dev/disk3 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *1.0 TB disk3
1: Windows_NTFS Documents2 1.0 TB disk3s1

需要记录的是 ntfs 磁盘的 NAME 信息,我这里有三个 ntfs 分区windows/Documents/Documents2.

然后继续执行命令,更新 fatab 文件:

1
sudo nano /etc/fstab

输入下列内容,并把 LABEL= 之后的内容替换为上面记录的分区的名字:

1
2
3
LABEL=Windows none ntfs rw,auto,nobrowse
LABEL=Documents none ntfs rw,auto,nobrowse
LABEL=Documents2 none ntfs rw,auto,nobrowse

重启之后即可。
注意:重启之后的移动磁盘不会在桌面上现实,必须要打开 Finder 才可以看到。