使用electron-builder打包mac应用后,无法安装提示未认证,在不提交appstore时,可以使用dmg认证,官方文档
- 使用苹果开发者账号生成develop-application类型证书,导出p12
- 在.zshrc文件中加入以下内容,配置证书信息
# electron builder CSC
export CSL_LINCSC_IDENTITY_AUTO_DISCOVERY=false
export CSC_LINK=/Users/xxx/mac-application.p12
export CSC_KEY_PASSWORD=xxxxxxx
- 项目内加入配置
"build": {
"productName": "测试",
"appId": "com.xx.xx",
"directories": {
"output": "release/${version}"
},
"files": [
"dist",
"electron"
],
"afterSign": "notarize.js",
"dmg": {
"sign": false,
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
}
# notarize.js
const { notarize } = require('@electron/notarize');
exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin') {
return;
}
const appName = context.packager.appInfo.productFilename;
return await notarize({
appPath: `${appOutDir}/${appName}.app`,
keychainProfile: 'xxxxx'
});
};
- 打包完成后的信息
electron-builder version=24.9.1 os=22.6.0
• loaded configuration file=package.json ("build" field)
• writing effective config file=release/1.0.4/builder-effective-config.yaml
• packaging platform=darwin arch=x64 electron=21.4.4 appOutDir=release/1.0.4/mac
• signing file=release/1.0.4/mac/测试.app identityName=Developer ID Application: The Sixth identityHash=xxxxx provisioningProfile=none
• building target=macOS zip arch=x64 file=release/1.0.4测试-1.0.4-mac.zip
• building target=DMG arch=x64 file=release/1.0.4/测试-1.0.4.dmg
• building block map blockMapFile=release/1.0.4/测试-1.0.4.dmg.blockmap
• building block map blockMapFile=release/1.0.4/测试-1.0.4-mac.zip.blockmap
- 认证完成