Electron executable not recognized by Nautilus
Asked Answered
Y

3

11

I'm not able to build an executable file of an Electron App with the following command:

electron-packager . electron-tutorial-app --overwrite --asar=true --platform=linux --arch=x64 --prune=true --out=release-builds

The build file, which is a shared library file (application/x-sharedlib), is not executing on Ubuntu 18. Instead, I'm getting the following error message when opening the file in Nautilus:

Could not display "electron-tutorial-app"

There is no application installed for "shared library" files. Do you want to search for an application to open this file?

[No] [Yes]

Is there any way around to do this?

Yulandayule answered 8/3, 2019 at 9:37 Comment(0)
I
12

TL;DR: the produced files are actually executables of a new format. There's nothing wrong with them. Nautilus/file managers mistakenly don't recognize them as executables. There are solutions, such as creating a *.desktop file to launch the application.

Analysis

This phenomenon occurs as a side-effect of a change in how Electron builds Linux binaries. The commit 9294facf changed the binary format from ELF to PIE. The change is quite small and only affects a single file (BUILD.gn). The change has landed in Electron starting with version 4.0.0.

File managers utilize the file command to decide what to do with a file (e.g. open an image viewer, a text editor or execute the file). file cannot distinguish between shared libraries and PIE executables and therefore misclassifies PIE files (see the corresponding bug report).

Solutions

Run from terminal

Since the problem only exists for graphical file managers, you can simply run the executable from the terminal or from a script. This is somewhat involved for non-technical end users and not what the OP wants.

Wait for upstream fix

Wait for file to recognize PIE as executable files. In turn, this will likely lead to file managers such as Nautilus to launch the PIEs correctly. It's not clear if or when this will happen. If it happens, it will likely only be included in future distro releases.

Use a desktop file

Create a desktop file to launch the application. This is a common way desktop applications are launched anyway.

Create a file called myapp.desktop with the following contents.

[Desktop Entry]
Name=My Application
Exec=/path/to/binary
Terminal=false
Type=Application
StartupNotify=true
Encoding=UTF-8

Then, mark the desktop file executable by issuing chmod +x myapp.desktop. Double clicking the file should launch the application as expected.


Further information

The corresponding discussion in the electron-packager project: https://github.com/electron-userland/electron-packager/issues/901. (Gist: This issue was not caused by electron-packager, look upstream)

The corresponding issue in the electron project is https://github.com/electron/electron/issues/15406. (Gist: they wanted to enable PIE on Linux. Not our bug, look upstream)

Indaba answered 8/3, 2019 at 13:18 Comment(2)
In case you don't know how to run from a terminal like me: $./app-name this was mentioned in the /issues/901 link above. I ran my app in UbuntuKadiyevka
Re the .desktop file approach, for those that don't know: remember to put that file in ~/.local/share/applications for the Gnome desktop to see it, scan it and create a menu/icon entry for your app in the global menu system. Also you probably don't need StartupNotify=true unless your app supports it developer.gnome.org/integration-guide/stable/…Concentration
Y
1

For Linux(Ubuntu):

  1. Downgrade Electron package:

    npm install [email protected] --save-dev

For global (If needed)

npm install -g [email protected]
  1. Execute electron-packager command - for linux:

    electron-packager . electron-tutorial-app --overwrite --asar --platform=linux --arch=all --prune=true --out=release-builds

This will result in 4 Linux folders(arch=all). Select a working executable according to your OS.

Yulandayule answered 8/3, 2019 at 13:21 Comment(1)
Downgrading Electron means missing out on many features and bugfixes and should only be considered in rare circumstances.Indaba
P
0

This is an issue when electron-packager is used to package a Linux app with Electron version 4.0.x, whereas there was no problem with previous Electron versions, such as 3.1.x.

For some reason, in Electron 4.0.x, the produced app file is a shared library instead of an executable.

From a Terminal window, running the file command on the app file path gives:

ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=b9e8ba37118dad1bf605affef41026f813215bc6, stripped

while it used to be:

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, stripped

Fortunately, it is still possible, albeit cumbersome, to run the app by launching it from a Terminal window, for instance by dragging the app file icon onto the terminal prompt, then typing Enter.

Pensive answered 8/3, 2019 at 11:17 Comment(1)
thanks, @Mikaeru, your answer led me to downgrade electron version and build with other parameters in electron-packager utility. This is working for at least Ubuntu Linux. So, now trying for windows machine also. Will update accordingly.Yulandayule

© 2022 - 2024 — McMap. All rights reserved.