clemp6r
clemp6r

Reputation: 3723

macOS cross-architecture build with Electron Builder gives "mach-o file, but is an incompatible architecture" runtime error

I have an Electron application built with Electron Builder for macOS and Windows.

Currently, for macos our application is built for the x64 target only (on an Intel machine), and then pushed to S3 for auto-updates. Now I want to build the application for both arm64 and x64 macos targets (note: I don't want to make an universal app for now).

I added the following configuration for Electron Builder:

    ...
    target: {
      target: 'default',
      arch: [
        'x64',
        'arm64'
      ]
    },
    ...

When I make the build on an Intel (x64) machine and then try to run the arm64 app on an Apple Silicon machine, I get the following error:

mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')

Also if I make the build on an Apple silicon machine and try to to run the Intel version on the same machine (with Rosetta), I get this:

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

The only thing that seem to work is building an Intel app on an Intel machine, and then building the arm64 app on an Apple Silicon machine. However this is not an option because I need the published latest.yml reference both, and this is not the case if I make two distinct publish from different machines (the latest one overwrites the previous one yaml file).

I tried adding buildDependenciesFromSource: true to the config root (as mentioned in #7349 or #6623) with no success.

Note our application uses an internal (proprietary) native node library. If I remove this native node library and its usage from the project, everything seems to work fine.

Any ideas?

PS: I also created an issue on Github because I'm not sure whether it is a bug in Electron Builder or something wrong on my side.

Upvotes: 0

Views: 999

Answers (1)

clemp6r
clemp6r

Reputation: 3723

This was due to electron-vite that copied an outdated version of the library. I just added this in electron-vite configuration:

{
  main: {
    ...
    build: {
      rollupOptions: { external: ["my-native-lib"] },
    },
  },
  ...
  },
}

Upvotes: 0

Related Questions