electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.64k stars 1.74k forks source link

Building for arch x64 mac on a arm64 mac #6433

Closed ammarrush closed 2 years ago

ammarrush commented 2 years ago

I am trying to build an electron app for both mac x64 and arm64 on a arm64 mac, the build process exits successfully but the built version for mac x64 does not open any window when I start it on a x64 mac, for arm64 Mac it works fine. I am using this command to build: electron-builder -m --x64 --arm64 --publish always

jediwade commented 2 years ago

Are you making use of the app.requestSingleInstanceLock() method in your main.js? Can you provide your package.json file?

ammarrush commented 2 years ago

Are you making use of the app.requestSingleInstanceLock() method in your main.js? Can you provide your package.json file?

I was not using app.requestSingleInstanceLock() but when I used it, the return value was true so this was the main instance.

I also want to add that I have the same problem even when I build only for x64 mac on my arm64 mac

{ "name": "zepto", "version": "1.1.1", "description": "https://www.zepto-ai.com/", "main": "main.js", "scripts": { "set-token": "node export.gh.token.docker.js", "publish-gh": "node publish.gh.release.js", "transpile": "node transpiler.dev.js", "postinstall": "electron-builder install-app-deps", "start:mix": "mix && npm run transpile", "build:mix": "mix -p && npm run transpile", "watch:mix": "mix watch", "hot:mix": "npx mix watch --hot", "hot:app": "electron . hot", "start:hot": "concurrently \"npm run hot:mix\" \"npm run hot:app\"", "start:app": "electron .", "build:app-m": "electron-builder -m --x64 --arm64 --publish always", "build:app-mwl": "npm run build:mix && electron-builder -mwl --publish never", "build:docker-app-l": "electron-builder -l --publish always", "build:app-w": "electron-builder build --win --publish never", "deploy:app": "npm run build:mix && electron-builder -mwl --publish always", "deploy:docker-app-wl": "electron-builder -wl --publish always && npm run publish-gh", "start": "npm run build:mix && npm run start:app", "watch": "concurrently \"npm run watch:mix\" \"npm run start:app\"", "build": "npm run build:mix && npm run build:app-mwl", "build:w": "npm run build:mix && npm run build:app-w", "deploy": "node --experimental-modules build.packages.mjs" }, "build": { "appId": "com.zepto-ai.zepto", "afterSign": "scripts/notarize.js", "directories": { "buildResources": "assets" }, "files": [ "index.html", ".jsc", "!.js", "!.js.map", "main.js", "app.jsc", "node_modules//*", "package.json", "bundle", "!bundle/js/index.js" ], "extraResources": [ "resources" ], "win": { "target": [ "nsis" ], "verifyUpdateCodeSignature": false, "icon": "assets/icon.ico" }, "nsis": { "installerIcon": "assets/icon.ico", "installerHeaderIcon": "assets/icon.ico", "deleteAppDataOnUninstall": true }, "mac": { "category": "public.app-category.productivity", "hardenedRuntime": true, "entitlements": "path/assets/entitlements.mac.plist", "entitlementsInherit": "path/assets/entitlements.mac.plist", "gatekeeperAssess": false, "target": [ "dmg" ] }, "linux": { "target": [ "AppImage" ] } }, "author": "Zepto-Ai", "license": "MIT", "private": true, "devDependencies": { "@babel/preset-react": "^7.14.5", "@gitbeaker/node": "^34.1.0", "@octokit/core": "^3.5.1", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.1", "browser-sync": "^2.27.5", "browser-sync-webpack-plugin": "^2.3.0", "chokidar": "^3.5.2", "concurrently": "^6.2.1", "cross-env": "^7.0.3", "cross-var": "^1.1.0", "electron": "^13.6.2", "electron-builder": "^22.14.7", "electron-is-dev": "^2.0.0", "electron-notarize": "^1.1.1", "electron-rebuild": "^3.2.3", "electron-reloader": "^1.2.1", "figlet": "^1.5.2", "laravel-mix": "6.0.31", "log-beautify": "^1.2.0", "node-gyp-build": "^4.2.2", "ora": "^6.0.1", "os-browserify": "^0.3.0", "postcss": "8.3.1", "prop-types": "^15.7.2", "raw-loader": "^4.0.2", "react-hot-loader": "^4.13.0", "react-refresh": "^0.10.0", "sass": "^1.39.0", "sass-loader": "^12.1.0", "simple-git": "^2.45.1", "webpack-hot-middleware": "^2.25.1", "webpack-node-externals": "^3.0.0" }, "dependencies": { "@creativebulma/bulma-tooltip": "^1.2.0", "active-win": "6.3.0", "amplitude": "^5.2.0", "amplitude-js": "^8.9.1", "axios": "^0.21.4", "bulma": "^0.9.3", "bytenode": "^1.3.3", "electron-devtools-installer": "^3.2.0", "electron-is-packaged": "^1.0.2", "electron-log": "^4.4.1", "electron-notifications": "^1.0.0", "electron-updater": "^4.4.6", "electron-util": "^0.17.2", "electron-windows-badge": "^1.1.0", "execa": "^5.1.1", "fix-path": "^4.0.0", "iconv": "^3.0.0", "js-base64": "^3.7.0", "js-cookie": "^3.0.1", "mixpanel-browser": "^2.41.0", "moment": "^2.29.1", "net": "^1.0.2", "node-abi": "^3.5.0", "node-loader": "^2.0.0", "node-notifier": "^10.0.0", "node-osascript": "^2.1.0", "node-powershell": "^4.0.0", "os": "^0.1.2", "path": "^0.12.7", "react": "^17.0.2", "react-alert": "^7.0.3", "react-dom": "^17.0.2", "react-icons": "^4.3.1", "react-modal": "^3.14.3", "react-router-dom": "^5.3.0", "react-test-renderer": "^17.0.2", "react-watcher": "^0.0.1", "sudo-prompt": "^9.2.1", "worker-timers": "^7.0.39", "xml2js": "^0.4.23" }, "repository": { "type": "git", "url": "xx" } }

jediwade commented 2 years ago

I'm not seeing anything wrong with the JSON. Interestingly, the backslashes you use for escapes were removed by GitHub from your reply (but they are in the notification email I got), so it looks like you have invalid JSON when you don't.

Have you tested your app on a Windows device before to know if a published app works at all or is this a recent development?

ammarrush commented 2 years ago

This could be because I edited the comment later on, but the JSON is valid.

The built app works for arm64 Mac but not for x64 Mac.

ammarrush commented 2 years ago

I want to add an important update, even if I build the app just for x64 mac I have the problem that app is built but when I open the app then nothing happens and the app is running in the tray but I do not see any windows.

I investigated further and asked my colleague to run the same code on his x64 mac and build the app using -m param, the built app which is an x64 mac app in dist folder works fine then, but for the same code when I build for x64 mac on an M1 mac machine the app does not open (neither on M1 machine nor on x64 machine).

jediwade commented 2 years ago

Sorry if this is a stupid question, but have you installed Rosetta on your M1 that lets you run Intel apps?

ammarrush commented 2 years ago

Yes, I have a few apps on my M1 mac which are intel apps and they work, but I have tested the x64 mac apps created by my M1 machine on x64 macs as well and they don’t work there too.

Just to update since electron 16.0.1 is the latest now, I test on that too but the result is the same.

jediwade commented 2 years ago

Sorry but I'm starting to run out of ideas. I looked at your package.json again and noticed you don't have a provisionprofile referenced. Is this an app that you have created a record for with an Apple developer account or just build/sign on your own?

ammarrush commented 2 years ago

I'm not sure what you mean by a provisionprofile, I do have an apple developer account I am able to sign and notarize the app using the afterSign property. I actually distributed the dmg and it was working for all kinds of macs but I updated electron-builder because I was having issues with autoUpdater, thought updating electron-builder would fix it. But now I have this problem :)

ammarrush commented 2 years ago

I am posting my after build messages, maybe it helps.

> zepto@1.1.1 build:app-m
> electron-builder -m --x64 --publish never

  • electron-builder  version=22.13.1 os=20.6.0
  • loaded configuration  file=package.json ("build" field)
  • electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies

To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
  • rebuilding native dependencies  dependencies=ffi-napi@4.0.3, iconv@3.0.1, ref-napi@3.0.3, iconv@2.3.5 platform=darwin arch=x64
  • packaging       platform=darwin arch=x64 electron=16.0.1 appOutDir=dist/mac
  • skipped macOS application code signing  reason=, see https://electron.build/code-signing CSC_IDENTITY_AUTO_DISCOVERY=false
  • building        target=DMG arch=x64 file=dist/zepto-1.1.1.dmg
  • Detected arm64 process, HFS+ is unavailable. Creating dmg with APFS - supports Mac OSX 10.12+
  • building block map  blockMapFile=dist/zepto-1.1.1.dmg.blockmap
jediwade commented 2 years ago

The joys of trying to work on a Mac. I'm facing a problem on my own app that I am trying to deploy to the Mac App Store. I'm new to some of this stuff and, for the MAS at least, it is my understanding you have to have created the provisionproflie (generated from the certs you created).

One last thing I can think of to try is to delete your node_modules folder and start with a fresh download of everything.

Because your app worked before on an older version of electron-builder, I'm going to guess that someone who works on that will have to investigate. For future people looking into this, what was the last version of electron-builder that worked for your app? Were any other packages updated?

ammarrush commented 2 years ago

I am not trying to put the app into Mac App Store so don’t know about that. Right now I was just trying to build the app and distribute.

I have tried deleting node_modules multiple times now, unfortunately no luck.

The last version it worked on was 21.2.0. I updated many packages in between, and I think that is why I run into other problems if I want to use that version to build.

ICoderMe commented 2 years ago

I think you haven't fully figured out the concept of packaging,you build an electron app for both mac x64 and arm64 on a arm64 mac,the arm64 app is works fine,because you mac is arm64,so the x64 app is need run on x64 mac device.

ammarrush commented 2 years ago

I think you haven't fully figured out the concept of packaging,you build an electron app for both mac x64 and arm64 on a arm64 mac,the arm64 app is works fine,because you mac is arm64,so the x64 app is need run on x64 mac device.

To my understanding an x64 app built on arm64 should work on x64 mac, and this is what I have tried and it doesn’t work. Whereas an x64 app built on x64 mac works. When I built for x64 and arm64 both, the x64 app did not work on x64 mac as I have stated before.

ICoderMe commented 2 years ago

sorry,I misunderstood what you mean.In theory, the x64 app and arm64 app compiled on the x64 and arm64 architecture macs can run normally on x64 and arm64 devices. But my experience is that the x64 app, arm64 app, and x64 app compiled on the x64 mac can run, but the arm64 cannot run normally on the arm64 device, indicating that the installation package is damaged.

ammarrush commented 2 years ago

sorry,I misunderstood what you mean.In theory, the x64 app and arm64 app compiled on the x64 and arm64 architecture macs can run normally on x64 and arm64 devices. But my experience is that the x64 app, arm64 app, and x64 app compiled on the x64 mac can run, but the arm64 cannot run normally on the arm64 device, indicating that the installation package is damaged.

Hmm in my case x64 app compiled on the arm64 mac is not running normally on x64 mac. By the way, if I use the same code base to compile for x64 app on an x64 mac it works without problems. If you have any suggestions how to fix this please let me know

Xtrendence commented 2 years ago

I'm also having this issue. No errors at all. When built on my x64 Mac, the x64 version works. But when built on my arm64 for x64 and then opened on the x64 Mac, it doesn't work.

I believe I've narrowed down the issue to a dependency called "leveldown", as when I compare the two .app outputs (what should be identical x64 applications), their only difference is the "leveldown" directory in the modules folder.

I haven't experimented further to see if this would work, but I'm thinking about keeping a copy of the "leveldown" folder created on the x64 Mac, and then replacing the broken one in the x64 app built on the arm64 device. Not sure if the compilation process actually involves writing any project-specific code to the "leveldown" folder, but if it doesn't, then this should hopefully work as a temporary solution so I don't have to dust off the old Mac every time I want to build the x64 version.

stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

labsforge commented 2 years ago

Hi, I think I had this issue too.. so I bought a mac-mini intel to build for x64, I assumed it had to be builded on the target arch machine. So my idea was to have 2 gitlab-runners with tags for arm64 and x64 and each machine builds their own dmg.. and it worked until I found out that I had to deal with the yml update file that was been overrided by the last machine to build. Then I found this thread.. with the same problem of builds of x64 on M1 that don't run on intel macs... any updates to share?

Omi0 commented 1 year ago

Are you making use of the app.requestSingleInstanceLock() method in your main.js? Can you provide your package.json file?

Hey @jediwade why was you asking about app.requestSingleInstanceLock() method? Because I have almost identical issue, and we're using this method in our index.ts file.

talksik commented 1 year ago

Same issue, I can't seem to build for x64 on an M2 mac.

However, solution for me was to build using 'universal' arch option in electron-builder. It's not in their docs, but you can add --universal flag instead of x64 and arm.

ufukomer commented 10 months ago

I can't build for x64 on my M1

kevincousy commented 7 months ago

Getting the same problem. Ask my M2 to build Arm64 and x86. The x86 app immediately closes.

ufukomer commented 7 months ago

Getting the same problem. Ask my M2 to build Arm64 and x86. The x86 app immediately closes.

I can try to help if you show me the list of libraries you are using. In my case, it was about some libraries that are impossible to build for another arch. I replaced the with alternative libs then the issue is solved.

murrayee commented 7 months ago

same as issue >26.