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

Mac端Electron Forge代码签名失败问题求助

macOS下Electron Forge代码签名与公证失败问题解决

问题核心分析

从错误日志看,关键问题有两个:

  1. This.app: code has no resources but signature indicates they must be present —— 签名标记要求应用包包含资源,但当前打包后的应用资源缺失
  2. 签名状态为adhoc,且TeamIdentifier=not set —— 未使用有效的开发者ID证书进行签名,导致签名不合法

具体解决步骤

1. 确认签名证书有效性

  • 打开终端执行以下命令,列出本地可用的分发用签名证书:
    security find-identity -v -p codesigning
    
  • 找到Developer ID Application类型的证书,复制其完整名称(或哈希值),确保settings.osx.identity配置的是这个值,不要用开发证书(iOS Development/Mac Development)

2. 修正Electron Forge的osxSign配置

修改forge.config.js中的osxSign段,移除不必要的参数并补全必要配置:

osxSign: {
  identity: "你的Developer ID Application证书完整名称",
  'hardened-runtime': true,
  entitlements: 'path/to/your/entitlements.mac.plist',
  'entitlements-inherit': 'path/to/your/entitlements.mac.plist',
  // 移除signature-flags: 'library' —— 该参数仅用于库文件签名,不适用于应用包
  'gatekeeper-assess': true, // 正式分发时建议开启,用于验证签名有效性
  verbose: true,
},
osxNotarize: {
  appleId: '你的Apple ID',
  appleIdPassword: '你的App专用密码', // 注意:必须是Apple ID管理页面生成的专用密码,而非普通密码
  teamId: '你的团队ID', // 从开发者后台或证书信息中获取
},

3. 修正Entitlements配置文件

确保entitlements.mac.plist包含Electron应用运行所需的 hardened runtime权限,分发用的基础配置如下:

<?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>
  <!-- Electron必需权限 -->
  <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.debugger</key>
  <true/> -->
</dict>
</plist>

4. 检查应用包资源完整性

  • 手动查看Electron打包生成的临时App包(日志中的/private/var/folders/.../tmp-JAFWup/This.app),确认Contents/Resources目录下有资源文件(如app.asar)
  • 如果资源缺失,检查Forge的packagerConfig配置,确保应用源码被正确打包:
    packagerConfig: {
      // 确保asar打包开启(默认开启)
      asar: true,
      // 如果有额外资源,添加到extraResources
      extraResources: ['./path/to/your/resources']
    }
    

5. 手动测试签名(排除Forge问题)

先跳过Forge,用原生codesign命令测试签名,定位问题:

codesign --deep --force --sign "你的Developer ID证书名称" --options runtime --entitlements path/to/entitlements.mac.plist --verbose /path/to/your.app

如果命令报错,根据终端提示直接修复(比如资源缺失补资源,证书错误换证书),成功后再用Forge执行完整流程

6. 清理缓存后重试

  • 删除Forge缓存目录:rm -rf ~/.electron-forge
  • 删除项目下的out目录(打包产物)
  • 重新执行打包签名命令:npm run make

内容的提问来源于stack exchange,提问作者Seth Brock

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 05:35:23