You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS Big Sur下electron-builder打包的公证后Electron应用无法打开

问题解决方案

核心诱因

你遇到的启动崩溃是开启hardenedRuntime后,权限配置(entitlements)缺失Electron运行必需的权限项导致的,公证流程本身没有问题,移除配置后相当于关闭了公证依赖的 hardened runtime 和自定义权限,所以能启动但无法完成公证。

具体修改步骤

1. 调整 entitlements 权限配置

有两种可选方案,根据你的分发场景选择:

方案A:不上架Mac App Store(推荐,适用于dmg/zip直接分发)

直接关闭macOS系统沙箱,同时补全hardened runtime必需的权限,修改entitlements.mac.plist内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <!-- 关闭系统沙箱,仅上架App Store才需要开启 -->
    <key>com.apple.security.app-sandbox</key>
    <false/>
    <!-- hardened runtime 必需权限 -->
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <!-- 保留你原有需要的权限 -->
    <key>com.apple.security.network.client</key>
    <true/>
    <key>com.apple.security.network.server</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
  </dict>
</plist>

方案B:需要上架Mac App Store

保留沙箱开启,同时补全hardened runtime必需的权限,在原有plist的dict块中新增以下权限项即可:

<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>

2. 补充 entitlements 继承配置

修改package.json的build.mac配置块,新增entitlementsInherit配置,确保应用的子进程、辅助程序能继承权限:

"mac": {
  "category": "public.app-category.music",
  "icon": "assets/appIcons/DJFlame Logo.icns",
  "hardenedRuntime": true,
  "entitlements": "./build/resources/entitlements.mac.plist",
  // 新增这一行
  "entitlementsInherit": "./build/resources/entitlements.mac.plist",
  "asarUnpack": "**/*.node"
}

3. 可选:升级依赖版本

你当前使用的electron-notarize@^1.0.0版本较老,若修改权限后仍有公证相关问题,可升级到最新稳定版,匹配你使用的electron-builder版本即可。

验证流程

修改完成后重新执行打包、签名、公证流程,完成后:

  1. 先启动应用确认无崩溃
  2. 再用spctl -a -t exec -vvv ./path/to/app/XXXX.app命令验证公证状态,显示source=Notarized Developer ID即为正常。

内容的提问来源于stack exchange,提问作者kidsonfilms-python-rules

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 02:00:04