electron使用electron-builder macOS windows 打包 签名 更新 上架

0. 前言

0.1 项目工程

看清目录结构,以便您阅读后续内容

0.2 参考资料

(1)macOS开发 证书等配置/打包后导出及上架

https://www.jianshu.com/p/c9c71f2f6eac首先需要为Mac App创建App ID: 填写信息如下---Description为"ProjectNameForMac"、Bundle ID为"com.CompanyName...https://www.jianshu.com/p/c9c71f2f6eac(2) electron应用提交到Mac App Store(MAS)全流程

https://www.jianshu.com/p/3f4765c319b6https://www.jianshu.com/p/3f4765c319b6

1. 安装electron-builder

2. macOS

2.1 创建 Certificates, Identifiers & Profiles Devices

在mac上安装xcode,打开xcode,然后按以下步骤操作。

(1) xcode的菜单栏:xcode > settings。登录apple id。

(2) 登录后,点击"Download Manual Profiles",再然后点击"Manage Certificates..."

再添加下面4个证书,创建后,该证书会自动在 网页上显示出来。

Sign In - Applehttps://developer.apple.com/account/resources/certificates/list

(3)打开以下网址,就会看到前一步创建的 证书

https://developer.apple.com/account/resources/certificates/list

(4) 创建 Identifiers

(5)创建 Devices(这个自行百度吧)

(6)创建Profiles

2.2 下载 Certificates Profiles 到本地 resource文件中

点击 Certificates 列表中的证书,然后点击"download"

在 Profiles 列表中点击"download"

2.3 检查macOS系统的证书配置情况

在 2.1 的步骤用xcode创建证书后,证书会显示在 钥匙串 中(自行百度打开这个程序)

(1) 登录>我的证书 中会看到以下两个证书(还有一个证书 Mac Developer ID Application的证书让我删除了,没在截图中)

(2) 登录>密钥 中会看到以下四个密钥

(3) 系统>我的证书 中会看到以下一个证书

(4) 系统>证书 中会看到以下两个证书

注意注意注意注意注意:

(1) 在每一张单个截图(不是所有截图,只指单个截图)中,证书不能重复,切记(血的教训,不要问为什么,我也不能给你解释清楚)。

如果重复了,就删除这些证书,然后把 2.2下载的cer后缀的证书 在macOS中双击,则就会安装到 "钥匙串访问"程序中

(2) 如果在 系统>证书 的列表中找到"Apple Worldwide Developer Relations Certification Authority",则从官网下载,至于下载哪个,我也忘记了,你自己 研究一下,大概是 截图中任意一个即可,呵呵。

(3)以上截图中证书的位置大抵如此,反正我就是这么成功的,我也没空再去研究了。如果你没成功,那可以参考我的截图中证书的位置,至少能成功。

https://www.apple.com/certificateauthority/

2.4 安装 provisionprofile 文件

我也不知道要不要安装,反正我是安装了,干脆你也安装吧。

安装后,在此处 会显示这玩意,貌似"greader_distribution.provisionprofile"装上上

2.4 导出 p12文件,以备后用

导出以下四个文件,导出时要求输入密码,你自己输入吧(假设我设置的密码为 gege123)

四个文件的名字各种对应哪个证书,你自己猜猜看。

2.5 再次查看证书情况

打开shell,输入如下命令

bash 复制代码
xcrun security find-identity -v -p codesigning

注意:不要他奶奶的切换到 sudo su,就用你的正常 用户

看到没,有4个证书安装成功了,如果不成功,就根据2.3重新来一次。

2.6 创建plist文件,以备后用

我也不知道为啥要搞这些文件,你搞就对了。

(1) entitlements.mas.loginhelper.plist

XML 复制代码
<?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>
        <key>com.apple.security.app-sandbox</key>
        <true/>
    </dict>
</plist>

(2) entitlements.mas.plist

文件中部分内容替换您自己的

XML 复制代码
<?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>
        <key>com.apple.security.app-sandbox</key>
        <true/>
        <key>com.apple.security.application-groups</key>
        <array>
            <string>GN5XP7HD2C.cn.rouhuasuan.greader (改成你自己的哈)</string>
        </array>

        <key>com.apple.application-identifier</key>
        <string>GN5XP7HD2C.cn.rouhuasuan.greader (改成你自己的哈)</string>
        
        <key>com.apple.security.network.client</key>
        <true/>
        <key>com.apple.security.network.server</key>
        <true/>
        
        <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.files.user-selected.read-only</key>
        <true/>
        <key>com.apple.security.files.user-selected.read-write</key>
        <true/>
        <key>com.apple.security.files.downloads.read-write</key>
        <true/>
    </dict>
</plist>

(3)entitlements.mas.inherit.plist

XML 复制代码
<?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>
        <key>com.apple.security.app-sandbox</key>
        <true/>
        <key>com.apple.security.inherit</key>
        <true/>
    </dict>
</plist>

2.7 package.json 配置

2.7.1 整体配置

(1)总体配置如下,但是根据不同的包格式,得做简单修改。

(2)在后文我也不解释有啥区别,你自己对比一下就知道了。

XML 复制代码
{
  "name": "greader",
  "productName": "greader",
  "version": "22.7.8",
  "description": "A reader with transparent window background, arbitrary window size, and auto-hide",
  "author": {
    "name": "youername",
    "email": "youeremail",
    "url": "youer office site"
  },
  "main": "src/bootstrap.js",
  "scripts": {
    "pack": " electron-builder --dir ",
    "win": " electron-builder --win --x64",
    "mac": " electron-builder --mac",
    "postinstall": "electron-builder install-app-deps"
  },
  "keywords": [],
  "license": "MIT",
  "dependencies": {
    "bytenode": "^1.5.0",
    "dayjs": "^1.11.8",
    "electron-log": "^4.4.8",
    "iconv-lite": "^0.6.3",
    "jschardet": "^3.0.0",
    "node-machine-id": "^1.1.12",
    "yarn": "^1.22.21"
  },
  "devDependencies": {
    "electron": "25.3.0",
    "electron-builder": "^24.6.4"
  },
  "build": {
    "appId": "GN5XP7HD2C.cn.rouhuasuan.greader",
    "productName": "Greader",
    "copyright": "Copyright © 2021 Alaso",
    "directories": {
      "buildResources": "build",
      "output": "dist"
    },
    "mac": {
      "category": "public.app-category.utilities",
      "target":["dmg", "pkg", "mas", "mas-dev"],
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "icon":"resource/mac.icns",
      "entitlements": "./resource/entitlements.mas.plist",
      "entitlementsInherit": "./resource/entitlements.mas.inherit.plist",
      "extendInfo": {
        "ElectronTeamID": "GN5XP7HD2C",
        "com.apple.developer.team-identifier": "GN5XP7HD2C",
        "com.apple.application-identifier": "GN5XP7HD2C.cn.rouhuasuan.greader",
        "Bundle name": "Greader",
        "LSHasLocalizedDisplayName": true,
        "ITSAppUsesNonExemptEncryption": "NO"
      }
    },
    "mas": {
      "type": "distribution",
      "identity": "penghui deng (GN5XP7HD2C)",
      "hardenedRuntime" : false,   
      "provisioningProfile": "./resource/greader_distribution.provisionprofile"
    },
    "masDev": {
      "type": "development",
      "identity": "penghui deng (8MUK7LXZQ5)",
      "hardenedRuntime": false,
      "provisioningProfile": "./resource/greader_development.provisionprofile"
    },
    "dmg": {
       
    },
    "pkg": {
      "identity": "penghui deng (GN5XP7HD2C)"
    },
    "win":{
      "target": ["nsis", "msi", "zip"],
      "icon": "resource/win.ico"
    },
    "nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true
    },
    "msi": {
      "menuCategory": "bestapp"
    }
  }
}

2.7.2 编译mas-dev

(1)package配置

XML 复制代码
{
  "name": "greader",
  "productName": "greader",
  "version": "22.7.8",
  "description": "A reader with transparent window background, arbitrary window size, and auto-hide",
  "author": {
    "name": "youername",
    "email": "youeremail",
    "url": "youer office site"
  },
  "main": "src/bootstrap.js",
  "scripts": {
    "pack": " electron-builder --dir ",
    "win": " electron-builder --win --x64",
    "mac": " electron-builder --mac",
    "postinstall": "electron-builder install-app-deps"
  },
  "keywords": [],
  "license": "MIT",
  "dependencies": {
    "bytenode": "^1.5.0",
    "dayjs": "^1.11.8",
    "electron-log": "^4.4.8",
    "iconv-lite": "^0.6.3",
    "jschardet": "^3.0.0",
    "node-machine-id": "^1.1.12",
    "yarn": "^1.22.21"
  },
  "devDependencies": {
    "electron": "25.3.0",
    "electron-builder": "^24.6.4"
  },
  "build": {
    "appId": "GN5XP7HD2C.cn.rouhuasuan.greader",
    "productName": "Greader",
    "copyright": "Copyright © 2021 Alaso",
    "directories": {
      "buildResources": "build",
      "output": "dist"
    },
    "mac": {
      "category": "public.app-category.utilities",
      "target":["mas-dev"],
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "icon":"resource/mac.icns",
      "entitlements": "./resource/entitlements.mas.plist",
      "entitlementsInherit": "./resource/entitlements.mas.inherit.plist",
      "extendInfo": {
        "ElectronTeamID": "GN5XP7HD2C",
        "com.apple.developer.team-identifier": "GN5XP7HD2C",
        "com.apple.application-identifier": "GN5XP7HD2C.cn.rouhuasuan.greader",
        "Bundle name": "Greader",
        "LSHasLocalizedDisplayName": true,
        "ITSAppUsesNonExemptEncryption": "NO"
      }
    },
    "mas": {
      "type": "distribution",
      "identity": "penghui deng (GN5XP7HD2C)",
      "hardenedRuntime" : false,   
      "provisioningProfile": "./resource/greader_distribution.provisionprofile"
    },
    "masDev": {
      "type": "development",
      "identity": "penghui deng (8MUK7LXZQ5)",
      "hardenedRuntime": false,
      "provisioningProfile": "./resource/greader_development.provisionprofile"
    },
    "dmg": {
       
    },
    "pkg": {
      "identity": "penghui deng (GN5XP7HD2C)"
    },
    "win":{
      "target": ["nsis", "msi", "zip"],
      "icon": "resource/win.ico"
    },
    "nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true
    },
    "msi": {
      "menuCategory": "bestapp"
    }
  }
}

(2)执行命令

XML 复制代码
export CSC_IDENTITY_AUTO_DISCOVERY=false
export CSC_LINK=/Users/dhzy/Desktop/project2/cer/appdev.p12
export CSC_KEY_PASSWORD=gege123
export CSC_NAME="penghui deng (8MUK7LXZQ5)"
yarn mac


注意:yarn mac 也可以用 npm run mac代替

2.7.3 编译mas

这个是要发布到 mac store的,不能直接运行

(1)package配置

XML 复制代码
{
  "name": "greader",
  "productName": "greader",
  "version": "22.7.8",
  "description": "A reader with transparent window background, arbitrary window size, and auto-hide",
  "author": {
    "name": "youername",
    "email": "youeremail",
    "url": "youer office site"
  },
  "main": "src/bootstrap.js",
  "scripts": {
    "pack": " electron-builder --dir ",
    "win": " electron-builder --win --x64",
    "mac": " electron-builder --mac",
    "postinstall": "electron-builder install-app-deps"
  },
  "keywords": [],
  "license": "MIT",
  "dependencies": {
    "bytenode": "^1.5.0",
    "dayjs": "^1.11.8",
    "electron-log": "^4.4.8",
    "iconv-lite": "^0.6.3",
    "jschardet": "^3.0.0",
    "node-machine-id": "^1.1.12",
    "yarn": "^1.22.21"
  },
  "devDependencies": {
    "electron": "25.3.0",
    "electron-builder": "^24.6.4"
  },
  "build": {
    "appId": "GN5XP7HD2C.cn.rouhuasuan.greader",
    "productName": "Greader",
    "copyright": "Copyright © 2021 Alaso",
    "directories": {
      "buildResources": "build",
      "output": "dist"
    },
    "mac": {
      "category": "public.app-category.utilities",
      "target":["mas"],
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "icon":"resource/mac.icns",
      "entitlements": "./resource/entitlements.mas.plist",
      "entitlementsInherit": "./resource/entitlements.mas.inherit.plist",
      "extendInfo": {
        "ElectronTeamID": "GN5XP7HD2C",
        "com.apple.developer.team-identifier": "GN5XP7HD2C",
        "com.apple.application-identifier": "GN5XP7HD2C.cn.rouhuasuan.greader",
        "Bundle name": "Greader",
        "LSHasLocalizedDisplayName": true,
        "ITSAppUsesNonExemptEncryption": "NO"
      }
    },
    "mas": {
      "type": "distribution",
      "identity": "penghui deng (GN5XP7HD2C)",
      "hardenedRuntime" : false,   
      "provisioningProfile": "./resource/greader_distribution.provisionprofile"
    },
    "masDev": {
      "type": "development",
      "identity": "penghui deng (8MUK7LXZQ5)",
      "hardenedRuntime": false,
      "provisioningProfile": "./resource/greader_development.provisionprofile"
    },
    "dmg": {
       
    },
    "pkg": {
      "identity": "penghui deng (GN5XP7HD2C)"
    },
    "win":{
      "target": ["nsis", "msi", "zip"],
      "icon": "resource/win.ico"
    },
    "nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true
    },
    "msi": {
      "menuCategory": "bestapp"
    }
  }
}

(2)执行命令

XML 复制代码
export CSC_IDENTITY_AUTO_DISCOVERY=false
export CSC_LINK=/Users/dhzy/Desktop/project2/cer/appdis.p12
export CSC_KEY_PASSWORD=greader123
export CSC_NAME="penghui deng (GN5XP7HD2C)"
yarn mac

2.7.4 编译dmg、pkg包

(1)package配置

XML 复制代码
{
  "name": "greader",
  "productName": "greader",
  "version": "22.7.8",
  "description": "A reader with transparent window background, arbitrary window size, and auto-hide",
  "author": {
    "name": "youername",
    "email": "youeremail",
    "url": "youer office site"
  },
  "main": "src/bootstrap.js",
  "scripts": {
    "pack": " electron-builder --dir ",
    "win": " electron-builder --win --x64",
    "mac": " electron-builder --mac",
    "postinstall": "electron-builder install-app-deps"
  },
  "keywords": [],
  "license": "MIT",
  "dependencies": {
    "bytenode": "^1.5.0",
    "dayjs": "^1.11.8",
    "electron-log": "^4.4.8",
    "iconv-lite": "^0.6.3",
    "jschardet": "^3.0.0",
    "node-machine-id": "^1.1.12",
    "yarn": "^1.22.21"
  },
  "devDependencies": {
    "electron": "25.3.0",
    "electron-builder": "^24.6.4"
  },
  "build": {
    "appId": "GN5XP7HD2C.cn.rouhuasuan.greader",
    "productName": "Greader",
    "copyright": "Copyright © 2021 Alaso",
    "directories": {
      "buildResources": "build",
      "output": "dist"
    },
    "mac": {
      "category": "public.app-category.utilities",
      "target":["dmg", "pkg"],
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "icon":"resource/mac.icns",
      "entitlements": "./resource/entitlements.mas.plist",
      "entitlementsInherit": "./resource/entitlements.mas.inherit.plist",
      "extendInfo": {
        "ElectronTeamID": "GN5XP7HD2C",
        "com.apple.developer.team-identifier": "GN5XP7HD2C",
        "com.apple.application-identifier": "GN5XP7HD2C.cn.rouhuasuan.greader",
        "Bundle name": "Greader",
        "LSHasLocalizedDisplayName": true,
        "ITSAppUsesNonExemptEncryption": "NO"
      }
    },
    "mas": {
      "type": "distribution",
      "identity": "penghui deng (GN5XP7HD2C)",
      "hardenedRuntime" : false,   
      "provisioningProfile": "./resource/greader_distribution.provisionprofile"
    },
    "masDev": {
      "type": "development",
      "identity": "penghui deng (8MUK7LXZQ5)",
      "hardenedRuntime": false,
      "provisioningProfile": "./resource/greader_development.provisionprofile"
    },
    "dmg": {
       
    },
    "pkg": {
      "identity": "penghui deng (GN5XP7HD2C)"
    },
    "win":{
      "target": ["nsis", "msi", "zip"],
      "icon": "resource/win.ico"
    },
    "nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true
    },
    "msi": {
      "menuCategory": "bestapp"
    }
  }
}

(2)执行命令

XML 复制代码
export CSC_IDENTITY_AUTO_DISCOVERY=false
export CSC_LINK=/Users/dhzy/Desktop/project2/cer/appdis.p12
export CSC_KEY_PASSWORD=greader123
export CSC_NAME="penghui deng (GN5XP7HD2C)"
yarn mac

2.7.5 相关异常问题

(1)如果出现什么 timestamp XXXX 的

没有联网,或者网络不好,多次尝试。也不要使用代理,代理可能导致失败。

(2)

相关推荐
喵叔哟24 分钟前
重构代码之取消临时字段
java·前端·重构
还是大剑师兰特1 小时前
D3的竞品有哪些,D3的优势,D3和echarts的对比
前端·javascript·echarts
王解1 小时前
【深度解析】CSS工程化全攻略(1)
前端·css
一只小白菜~1 小时前
web浏览器环境下使用window.open()打开PDF文件不是预览,而是下载文件?
前端·javascript·pdf·windowopen预览pdf
方才coding1 小时前
1小时构建Vue3知识体系之vue的生命周期函数
前端·javascript·vue.js
阿征学IT1 小时前
vue过滤器初步使用
前端·javascript·vue.js
王哲晓1 小时前
第四十五章 Vue之Vuex模块化创建(module)
前端·javascript·vue.js
丶21361 小时前
【WEB】深入理解 CORS(跨域资源共享):原理、配置与常见问题
前端·架构·web
发现你走远了1 小时前
『VUE』25. 组件事件与v-model(详细图文注释)
前端·javascript·vue.js
Mr.咕咕1 小时前
Django 搭建数据管理web——商品管理
前端·python·django