Electron--electron-builder打包流程和下载不了包解决方法(window和Mac)

windows打包

安装

安装在上一篇文章里
关于electron-builder打包可以有两种方案:

  1. 打包成文件夹及绿色免安装:
    electron-builder --dir(依赖winCodeSign)
    2.打包成exe的安装包
    electron-builder (依赖winCodeSign和nsis)
    electron-builder有一些依赖包如 【winCodeSign】、【nsis】;在科学上网的情况下,直接执行命令就会自动处理相关依赖,但天朝基本不科学上网,所以会出现包安装超时等的一些情况,这个时候就需要手动安装:

1.第一步:下载wincodesign包 链接: https://github.com/electron-userland/electron-builder-binaries/releases

2.第二步:选择Source code (zip)下载并解压,里面已经包含nsis

3.第三步:在%LOCALAPPDATA%(C:\Users\Administrator\AppData\Local\electron-builder\Cache\winCodeSign)如果不存在就新建electron-builder\cache\

4.第四步:将Source code (zip)解压到第三步的目录下,根据错误提示的版本在对于的包下面新建对于的版本,并把文件移动到目录下,便可正常打包,如图:
在这里插入图片描述

mac打包

electron-builder --win --x64

运行以上命令会抛错误:
在这里插入图片描述

• electron-builder  version=22.10.5 os=20.3.0
  • writing effective config  file=dist/builder-effective-config.yaml
  • packaging       platform=win32 arch=x64 electron=13.1.1 appOutDir=dist/win-unpacked
  • Unpacking electron zip  zipPath=undefined
  • default Electron icon is used  reason=application icon is not set
  • downloading     url=https://github.com/electron-userland/electron-builder-binaries/releases/download/wine-4.0.1-mac/wine-4.0.1-mac.7z size=19 MB parts=3
^C  • canceling       signal=interrupt
  • cancelled by SIGINT
  ⨯ sha512 checksum mismatch, expected aCUQOyuPGlEvLMp0lPzb54D96+8IcLwmKTMElrZZqVWtEL1LQC7L9XpPv4RqaLX3BOeSifneEi4j9DpYdC1DCA==, got 1iqyfg0+72nqyW1/fDGvIoHUFVuANWYKMEBN3QCXuWb7o3L6Q5X2CxVx8ptFMiyasR9U+73kzxY84I4gihNHHA==
github.com/develar/app-builder/pkg/download.(*ActualLocation).concatenateParts
        /Volumes/data/Documents/app-builder/pkg/download/ActualLocation.go:158
github.com/develar/app-builder/pkg/download.(*Downloader).DownloadResolved
        /Volumes/data/Documents/app-builder/pkg/download/downloader.go:176
github.com/develar/app-builder/pkg/download.(*Downloader).DownloadNoRetry
        /Volumes/data/Documents/app-builder/pkg/download/downloader.go:133
github.com/develar/app-builder/pkg/download.(*Downloader).Download
        /Volumes/data/Documents/app-builder/pkg/download/downloader.go:112
github.com/develar/app-builder/pkg/download.DownloadArtifact
        /Volumes/data/Documents/app-builder/pkg/download/artifactDownloader.go:107
github.com/develar/app-builder/pkg/wine.executeMacOsWine
        /Volumes/data/Documents/app-builder/pkg/wine/wine.go:124
github.com/develar/app-builder/pkg/wine.ExecWine
        /Volumes/data/Documents/app-builder/pkg/wine/wine.go:69
github.com/develar/app-builder/pkg/rcedit.editResources
        /Volumes/data/Documents/app-builder/pkg/rcedit/rcedit.go:61
github.com/develar/app-builder/pkg/rcedit.ConfigureCommand.func1
        /Volumes/data/Documents/app-builder/pkg/rcedit/rcedit.go:25
github.com/alecthomas/kingpin.(*actionMixin).applyActions
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/actions.go:28
github.com/alecthomas/kingpin.(*Application).applyActions
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:557
github.com/alecthomas/kingpin.(*Application).execute
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:390
github.com/alecthomas/kingpin.(*Application).Parse
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:222
main.main
        /Volumes/data/Documents/app-builder/main.go:90
runtime.main
        /usr/local/Cellar/go/1.15.5/libexec/src/runtime/proc.go:204
runtime.goexit
        /usr/local/Cellar/go/1.15.5/libexec/src/runtime/asm_amd64.s:1374
github.com/develar/app-builder/pkg/download.(*Downloader).DownloadResolved
        /Volumes/data/Documents/app-builder/pkg/download/downloader.go:178
github.com/develar/app-builder/pkg/download.(*Downloader).DownloadNoRetry
        /Volumes/data/Documents/app-builder/pkg/download/downloader.go:133
github.com/develar/app-builder/pkg/download.(*Downloader).Download
        /Volumes/data/Documents/app-builder/pkg/download/downloader.go:112
github.com/develar/app-builder/pkg/download.DownloadArtifact
        /Volumes/data/Documents/app-builder/pkg/download/artifactDownloader.go:107
github.com/develar/app-builder/pkg/wine.executeMacOsWine
        /Volumes/data/Documents/app-builder/pkg/wine/wine.go:124
github.com/develar/app-builder/pkg/wine.ExecWine
        /Volumes/data/Documents/app-builder/pkg/wine/wine.go:69
github.com/develar/app-builder/pkg/rcedit.editResources
        /Volumes/data/Documents/app-builder/pkg/rcedit/rcedit.go:61
github.com/develar/app-builder/pkg/rcedit.ConfigureCommand.func1
        /Volumes/data/Documents/app-builder/pkg/rcedit/rcedit.go:25
github.com/alecthomas/kingpin.(*actionMixin).applyActions
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/actions.go:28
github.com/alecthomas/kingpin.(*Application).applyActions
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:557
github.com/alecthomas/kingpin.(*Application).execute
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:390
github.com/alecthomas/kingpin.(*Application).Parse
        /Volumes/data/go/pkg/mod/github.com/alecthomas/kingpin@v2.2.6+incompatible/app.go:222
main.main
        /Volumes/data/Documents/app-builder/main.go:90
runtime.main
        /usr/local/Cellar/go/1.15.5/libexec/src/runtime/proc.go:204
runtime.goexit
        /usr/local/Cellar/go/1.15.5/libexec/src/runtime/asm_amd64.s:1374  
  • Above command failed, retrying 3 more times

解决方法:
把downloading上的包下载下来放到
/Users/自己的电脑名称/Library/Caches/electron-builder/winCodeSign
在这里插入图片描述
如果还是不行就在拷贝一份到
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,下面是基于 React 和 Electron 并使用 electron-builder 进行打包的教程: 1. 创建 React 应用 首先,我们需要使用 create-react-app 工具创建一个 React 应用。在命令行中运行以下命令: ``` npx create-react-app my-electron-app ``` 这会在当前目录下创建一个名为 `my-electron-app` 的新应用。 2. 添加 Electron 接下来,我们需要在项目中添加 Electron。我们可以使用 `electron` 和 `electron-builder` 库来实现这一点。 在命令行中运行以下命令: ``` cd my-electron-app npm install --save-dev electron electron-builder ``` 3. 添加 Electron 入口文件 我们需要创建一个新文件 `public/electron.js`,这是 Electron 的入口文件。在这个文件中,我们需要引入 `electron` 模块并创建一个新的 Electron 窗口。 ```js const { app, BrowserWindow } = require('electron') function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } }) win.loadURL('http://localhost:3000') } app.whenReady().then(() => { createWindow() app.on('activate', function () { if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) ``` 这个文件创建了一个新的 Electron 窗口,并在窗口中加载了 React 应用的 `http://localhost:3000` 页面。 4. 修改 package.json 文件 我们需要修改 `package.json` 文件中的一些字段,以便 electron-builder 能够正确地打包我们的应用。 ```json { "name": "my-electron-app", "version": "0.1.0", "homepage": "./", "main": "public/electron.js", "build": { "appId": "com.example.my-electron-app", "productName": "My Electron App", "directories": { "output": "build" }, "files": [ "build/**/*", "node_modules/**/*", "public/**/*" ], "mac": { "category": "public.app-category.developer-tools", "icon": "public/icon.icns" }, "win": { "icon": "public/icon.ico" } } } ``` 这个文件中的 `main` 字段告诉 electron-builder 我们的 Electron 入口文件在 `public/electron.js`。`build` 字段中的其他字段指定了打包的一些设置,例如应用的 ID、名称、输出目录、文件列表和图标。 5. 添加打包脚本 最后,我们需要在 `package.json` 文件中添加一个打包脚本。 ```json { "scripts": { "start": "react-scripts start", "build": "react-scripts build", "pack": "electron-builder --dir", "dist": "electron-builder" } } ``` 这些脚本中的 `pack` 脚本会在开发模式下打包应用程序,而 `dist` 脚本会在生产模式下打包应用程序。 6. 运行应用 现在,我们可以运行应用程序。在命令行中运行以下命令: ``` npm start ``` 这将启动 React 应用程序。 然后,在另一个命令行窗口中运行以下命令: ``` npm run pack ``` 这将使用 `electron-builder` 打包应用程序,并在输出目录中生成一个可执行文件。 如果您想要构建一个安装程序,您可以运行以下命令: ``` npm run dist ``` 这将打包应用程序,并在输出目录中生成一个安装程序。 这就是使用 React 和 Electron 并使用 electron-builder 进行打包的教程。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值