当前位置: 首页 > 文档资料 > Electron 中文文档 >

构建步骤(Windows)

优质
小牛编辑
130浏览
2023-12-01

遵循下面的步骤, 在 Windows 平台上构建 Electron。

Build Instructions (Windows)

Follow the guidelines below for building Electron on Windows.

基本要求

  • Windows 10 / Server 2012 R2 或更高版本
  • Visual Studio 2017 15.7.2 或更高版本 - 免费下载 VS 2017 社区版
  • Python 2.7.10 或更高版本

    • 与下面 depot_tools 的安装说明不同,你必须安装 2.7.10 以上版本的 Python(支持 TLS 1.2)。 为此,应确保 PATH 中 Python 的安装目录在 depot_tools 之前。 目前 depot_tools 仍捆绑 Python 2.7.6,这将导致 gclient 命令失效(见 https://crbug.com/868864)。
    • Python for Windows (pywin32) 扩展对于构建流程也是必需的。
  • Node.js
  • Git
  • 如果您计划使用Windows SDK 10.0.15063.468的Windows调试工具 创建一个完整的发行版 symstore.exe 用来创建符号 保存于 .pdb 文件。

    • 不同版本的SDK可以同时安装 安装 SDK,打开 Visual Studio 安装程序,选择 更改单个组件,向下滚动并选择适当的 要安装的 Windows SDK 组件。 另一个选择是查看 windows SDK 和仿真器存档 并分别下载 SDK 的独立版本。
    • 还必须安装 SDK 调试工具。 如果已安装了 Windows 10 SDK 通过 Visual Studio 安装程序,然后可以用以下方式安装它们: 控制面板程序程序和功能→选择“Windows 软件开发工具包”→ 更改更改→选中“Windows 调试工具”→更改。 或者,您可以下载独立的 SDK 安装程序,并且使用它安装调试工具。

如果您当前没有安装 Windows, dev.microsoftedge.com 上有时间限制的 Windows 版本,你可以用来构建 Electron。

构建 Electron 完全由命令行脚本完成,无法通过 Visual Studio 完成。 您可以使用任何编辑器开发 Electron,但将来将会使用 Visual Studio 构建支持。

注意: 即使 Visual Studio 不用于构建,但是仍然需要,因为我们需要它提供的构建工具链。

Prerequisites

  • Windows 10 / Server 2012 R2 or higher
  • Visual Studio 2017 15.7.2 or higher - download VS 2019 Community Edition for free

    • See the Chromium build documentation for more details on which Visual Studio components are required.
    • If your Visual Studio is installed in a directory other than the default, you'll need to set a few environment variables to point the toolchains to your installation path.

      • vs2019_install = DRIVE:pathtoMicrosoft Visual Studio2019Community (replace 2019 and Community with your installed versions)
      • WINDOWSSDKDIR = DRIVE:pathtoWindows Kits10
  • Python 2.7.10 or higher

    • Contrary to the depot_tools setup instructions linked below, you will need to use your locally installed Python with at least version 2.7.10 (with support for TLS 1.2). To do so, make sure that in PATH, your locally installed Python comes before the depot_tools folder. Right now depot_tools still comes with Python 2.7.6, which will cause the gclient command to fail (see https://crbug.com/868864).
    • Python for Windows (pywin32) Extensions is also needed in order to run the build process.
  • Node.js
  • Git
  • Debugging Tools for Windows of Windows SDK 10.0.15063.468 if you plan on creating a full distribution since symstore.exe is used for creating a symbol store from .pdb files.

    • Different versions of the SDK can be installed side by side. To install the SDK, open Visual Studio Installer, select ChangeIndividual Components, scroll down and select the appropriate Windows SDK to install. Another option would be to look at the Windows SDK and emulator archive and download the standalone version of the SDK respectively.
    • The SDK Debugging Tools must also be installed. If the Windows 10 SDK was installed via the Visual Studio installer, then they can be installed by going to: Control PanelProgramsPrograms and Features → Select the "Windows Software Development Kit" → ChangeChange → Check "Debugging Tools For Windows" → Change. Or, you can download the standalone SDK installer and use it to install the Debugging Tools.

If you don't currently have a Windows installation, dev.microsoftedge.com has timebombed versions of Windows that you can use to build Electron.

Building Electron is done entirely with command-line scripts and cannot be done with Visual Studio. You can develop Electron with any editor but support for building with Visual Studio will come in the future.

Note: Even though Visual Studio is not used for building, it's still required because we need the build toolchains it provides.

构建

参照Build Instructions: GN

Building

See Build Instructions: GN

32 位构建

为了构建 32bit 版本,您需要通过 target_cpu = “x86" 作为 GN 参数。 可以使用不同的 GN 输出目录(例如, out/Release-x86) 和不同的参数,在 64 位目标旁边构建 32 位目标。

$ gn gen out/Release-x86 --args="import("//electron/build/args/release.gn") target_cpu="x86""

其他构建步骤完全一样。

32bit Build

To build for the 32bit target, you need to pass target_cpu = "x86" as a GN arg. You can build the 32bit target alongside the 64bit target by using a different output directory for GN, e.g. out/Release-x86, with different arguments.

$ gn gen out/Release-x86 --args="import("//electron/build/args/release.gn") target_cpu="x86""

The other building steps are exactly the same.

Visual Studio 项目

要生成 Visual Studio 项目,可以传递 --ide=vs2017 参数 给 gn gen

$ gn gen out/Debug --ide=vs2017

Visual Studio project

To generate a Visual Studio project, you can pass the --ide=vs2017 parameter to gn gen:

$ gn gen out/Debug --ide=vs2017

故障排查

Troubleshooting

Command xxxx not found

如果你遇到了一个错误,类似 Command xxxx not found, 可以尝试使用 VS2015 Command Prompt 控制台来执行构建脚本.

Command xxxx not found

If you encountered an error like Command xxxx not found, you may try to use the VS2015 Command Prompt console to execute the build scripts.

Fatal internal compiler error: C1001

确保你已经安装了 Visual Studio 的最新安装包.

Fatal internal compiler error: C1001

Make sure you have the latest Visual Studio update installed.

LNK1181: cannot open input file 'kernel32.lib'

重新安装 32位的 Node.js.

LNK1181: cannot open input file 'kernel32.lib'

Try reinstalling 32bit Node.js.

Error: ENOENT, stat 'C:UsersUSERNAMEAppDataRoamingnpm'

创建那个目录 应该可以解决问题:

$ mkdir ~AppDataRoamingnpm

Error: ENOENT, stat 'C:UsersUSERNAMEAppDataRoamingnpm'

Creating that directory should fix the problem:

$ mkdir ~AppDataRoamingnpm

node-gyp is not recognized as an internal or external command

如果你使用 Git Bash 来构建,或许会遇到这个错误,可以使用 PowerShell 或 VS2015 Command Prompt 来代替.

node-gyp is not recognized as an internal or external command

You may get this error if you are using Git Bash for building, you should use PowerShell or VS2015 Command Prompt instead.

无法在“…”处创建目录:文件名太长

node.js 有一些 极长的路径名,默认情况下,windows 上的 git 不能正确处理长路径名(即使 windows 支持它们)。 这应该可以修复它:

$ git config --system core.longpaths true

cannot create directory at '...': Filename too long

node.js has some extremely long pathnames, and by default git on windows doesn't handle long pathnames correctly (even though windows supports them). This should fix it:

$ git config --system core.longpaths true

错误:使用未声明的标识符“DefaultDelegateCheckMode”

在使用 Windows 驱动程序工具包安装 Windows 调试工具时,可能会在构建期间发生这种情况。卸载 Windows 驱动程序工具包并使用上述步骤安装调试工具。

error: use of undeclared identifier 'DefaultDelegateCheckMode'

This can happen during build, when Debugging Tools for Windows has been installed with Windows Driver Kit. Uninstall Windows Driver Kit and install Debugging Tools with steps described above.

导入错误:没有名为 win32file 的模块

确保已使用 pip install pywin32 安装了 pywin32

ImportError: No module named win32file

Make sure you have installed pywin32 with pip install pywin32.