admin管理员组

文章数量:1278914

I have a problem with building separate images for macOS for both main architectures for an electron-based application. I use electron-builder with this config:

electron-builder.yml:

# ...
npmRebuild: true
mac:
  target:
    - target: default
      arch: x64
    - target: default
      arch: arm64
  entitlementsInherit: build/entitlements.mac.plist
  extendInfo:
    - NSCameraUsageDescription: Application requests access to the device's camera.
    - NSMicrophoneUsageDescription: Application requests access to the device's microphone.
    - NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
    - NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
  notarize: false
  category: public.app-category.productivity
  artifactName: ${name}-macos-${version}-${arch}.${ext}
dmg:
  artifactName: ${name}-${version}-${arch}.${ext}
# ...

As you can see I have both the ARM64 and the X64 architectures set as targets, with npmRebuild set as true. I also have postinstall defined within the package.json file:

{
  // ...
  "scripts": {
    // ...
    "postinstall": "electron-builder install-app-deps",
    // ...
  }
}

Both DMG files build successfully and seemingly both have the proper architecture.

However, while running the X64 application, I always get this error:

.../Release/better_sqlite3.node' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64h' or 'x86_64'))

When building the application, it seemingly does the proper thing:

  • executing @electron/rebuild  electronVersion=34.0.2 arch=x64 buildFromSource=false appDir=./
  • installing native dependencies  arch=x64
  • preparing       moduleName=better-sqlite3 arch=x64
  • finished        moduleName=better-sqlite3 arch=x64
  • completed installing native dependencies
  • packaging       platform=darwin arch=x64 electron=34.0.2 appOutDir=dist/mac
# ...
  • Detected arm64 process, HFS+ is unavailable. Creating dmg with APFS - supports Mac OSX 10.12+
  • installing native dependencies  arch=arm64
  • preparing       moduleName=better-sqlite3 arch=arm64
  • finished        moduleName=better-sqlite3 arch=arm64
  • completed installing native dependencies
  • packaging       platform=darwin arch=arm64 electron=34.0.2 appOutDir=dist/mac-arm64

本文标签: npmBuild both ARM64 and X64 macOS targets with electronbuilder including their dependenciesStack Overflow