跳转到主内容

构建步骤(macOS)

请按照下面的指南在macOS下构建 Electron,以此创建自定义 Electron 二进制文件。 For bundling and distributing your app code with the prebuilt Electron binaries, see the application distribution guide.

基本要求

  • macOS >= 11.6.0
  • Xcode. 所需的确切版本取决于您正在构建的分支。 但最新版本的 Xcode 通常是构建 main 分支一个很好的选择
  • node.js (外部)
  • Python >= 3.7

在ARM64平台上编译的前置需求

  • Rosetta 2
    • 如果需要在x64和arm64机器上交叉编译依赖项,我们建议安装Rosetta。 可以使用softwareupdate命令行工具来安装Rosetta。
    • $ softwareupdate --install-rosetta

构建Electron

See Build Instructions: GN.

故障排查

Xcode "incompatible structure"错误 (MacOS arm64-specific)

如果已安装Xcode和Xcode命令行工具($ xcode -select --install,或直接从这里下载安装好正确版本),但堆栈跟踪显示不同,请按如下方式操作:

xcrun: error: unable to load libxcrun
(dlopen(/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode.app/Contents/Developer/usr/lib/libxcrun.dylib), 0x0005):
tried: '/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode.app/Contents/Developer/usr/lib/libxcrun.dylib)'
(mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode-11.1.0.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode-11.1.0.app/Contents/Developer/usr/lib/libxcrun.dylib)' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))).`

If you are on arm64 architecture, the build script may be pointing to the wrong Xcode version (11.x.y doesn't support arm64). 打开 /Users/<user>/.electron_build_tools/third_party/Xcode/,将 Xcode-13.3.0.app 重命名为 Xcode.app,以确保使用正确的 Xcode 版本。

Certificates fail to verify

installing certifi will fix the following error:

________ running 'python3 src/tools/clang/scripts/update.py' in '/Users/<user>/electron'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 5 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 10 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 20 s ...

This issue has to do with Python 3.6 using its own copy of OpenSSL in lieu of the deprecated Apple-supplied OpenSSL libraries. certifi adds a curated bundle of default root certificates. This issue is documented in the Electron repo here. Further information about this issue can be found here and here.