My Flatpak fails, unable to find wayland and network

I am trying to repackage an proprietary app that’s only available as an AppImage as a Flatpak.

Edit: I added this to the manifest (stolen from Nextcloud Client):

base: io.qt.qtwebengine.BaseApp
base-version: 5.15-23.08

and now the error output is:

usage: event_rpcgen.py [options] rpc-file [[h-file] c-file]
event_rpcgen.py: error: the following arguments are required: rpc_file

This is the previous output before I added qtwebengine:

However, when I try to run it, I get this error:

user@tumbleweed:~/flatpak-builder> flatpak run com.infomaniak.kdrive
kDrive server starting
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
_IceTransSocketUNIXConnect: Cannot connect to non-local host localhost.localdomain
_IceTransSocketUNIXConnect: Cannot connect to non-local host localhost.localdomain
Qt: Session management error: Could not open network socket
kDrive server initialization error: Unable to open parameters database.

This is my manifest (note - edited since first posted here):

app-id: com.infomaniak.kdrive

runtime: org.kde.Platform
runtime-version: 5.15-23.08
sdk: org.kde.Sdk

finish-args:
  - --device=dri
  - --socket=wayland
  - --socket=x11
  - --share=network
  - --share=ipc
  - --filesystem=home
  - --talk-name=org.freedesktop.Notifications
  - --talk-name=org.freedesktop.secrets
  - --talk-name=org.kde.StatusNotifierWatcher
  - --talk-name=org.kde.kwalletd5

modules:
  - name: kdrive
    buildsystem: simple
    build-commands:
      # Extract the Appimage
     - chmod a+x kDrive.AppImage
     - ./kDrive.AppImage --appimage-extract >/dev/null
     - chmod -R --reference=kDrive.AppImage squashfs-root
     - rm ./kDrive.AppImage
     # Patch .destop file with the new icon and binary location
     - sed -i -e 's/Icon.*/Icon=com.infomaniak.kdrive/' squashfs-root/kDrive_client.desktop
     - sed -i -e 's/Exec.*/Exec=start-kdrive-flatpak.sh %F/' squashfs-root/kDrive_client.desktop
     # Move things into place
     - mkdir /app/kdrive
     - cp -r squashfs-root/* /app/kdrive
     - install -Dm644 squashfs-root/kDrive_client.desktop /app/share/applications/com.infomaniak.kdrive.desktop
     - |
       for s in 16 32 48 64 128 256 512; do
         install -Dm644 squashfs-root/usr/share/icons/hicolor/${s}x${s}/apps/kdrive-win.png /app/share/icons/hicolor/${s}x${s}/apps/com.infomaniak.kdrive.png
       done
     - install -Dm644 com.infomaniak.kdrive.appdata.xml /app/share/appdata/com.infomaniak.kdrive.appdata.xml
     - install -Dm544 start-kdrive-flatpak.sh /app/bin/start-kdrive-flatpak.sh
    sources:
      - type: file
        url: https://download.storage.infomaniak.com/drive/desktopclient/kDrive-3.5.7.20240124-amd64.AppImage
        sha256: ab99aa9252d9e7c613d2a4247d368a6369926062b54ad7ddbb1ab36f1d591d4b
        only-arches:
         - x86_64
        dest-filename: kDrive.AppImage
      - type: file
        url: https://download.storage.infomaniak.com/drive/desktopclient/kDrive-3.5.7.20240124-arm64.AppImage
        sha256: 894f7544bfe302d747dd77d0769f69889e0bee6f1e6dbdce1c3410bd864519f3
        only-arches:
         - aarch64
        dest-filename: kDrive.AppImage
      - type: file
        path: com.infomaniak.kdrive.appdata.xml
      - type: script
        dest-filename: start-kdrive-flatpak.sh
        commands:
          - /app/kdrive/AppRun "$@"
# potentially add some kind of update checking here

For added context, this is the end of the output of the flatpak-builder --user --install --force-clean command:

Committing stage build-kdrive to cache
Cleaning up
Renaming com.infomaniak.kdrive.appdata.xml to share/metainfo/com.infomaniak.kdrive.metainfo.xml
Running appstreamcli compose
Only accepting components: com.infomaniak.kdrive, com.infomaniak.kdrive.desktop
Processing directory: /home/user/flatpak-builder/.flatpak-builder/rofiles/rofiles-5Hdjo4/files
Composing metadata...

** (appstreamcli-compose:4440): CRITICAL **: 16:35:24.411: as_icon_set_scale: assertion 'scale >= 1' failed
Success!
Committing stage cleanup to cache
Finishing app
Exporting share/applications/com.infomaniak.kdrive.desktop
Exporting share/icons/hicolor/16x16/apps/com.infomaniak.kdrive.png
Exporting share/icons/hicolor/32x32/apps/com.infomaniak.kdrive.png
Exporting share/icons/hicolor/48x48/apps/com.infomaniak.kdrive.png
Exporting share/icons/hicolor/64x64/apps/com.infomaniak.kdrive.png
Exporting share/icons/hicolor/128x128/apps/com.infomaniak.kdrive.png
Exporting share/icons/hicolor/256x256/apps/com.infomaniak.kdrive.png
Exporting share/icons/hicolor/512x512/apps/com.infomaniak.kdrive.png
Exporting share/metainfo/com.infomaniak.kdrive.metainfo.xml
Using start-kdrive-flatpak.sh as command
Please review the exported files and the metadata
Committing stage finish to cache
Exporting com.infomaniak.kdrive to repo
Commit: 751b3255d9acc3b20eda53524439200d9c7f5673f18f76dfa661d36bf78b5030
Metadata Total: 403
Metadata Written: 1
Content Total: 762
Content Written: 0
Content Bytes Written: 0 (0 bytes)
Exporting com.infomaniak.kdrive.Debug to repo
Commit: cf268a3d3678f6adc6dd2fe157b59950bb81b16e00c7c8f9feed7399a17fee8c
Metadata Total: 71
Metadata Written: 1
Content Total: 121
Content Written: 0
Content Bytes Written: 0 (0 bytes)
Installing app/com.infomaniak.kdrive/x86_64/master
Pruning cache

You should use --socket=fallback-x11 instead of x11 when using Wayland

Thank you. I now replaced --socket=x11 with --socket=fallback-x11 (or am I meant to have both?) and I also removed qtwebengine as the base-app to get rid of that rcp_file error.

It still doesn’t run though:

kDrive server starting
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vkkhrdisplay, vnc, xcb.

Server stoped with signal 6

Reinstalling, as suggested, didn’t fix it.

I’ve made some progress:

user@tumbleweed:~/flatpak-builder> flatpak run com.infomaniak.kdrive
kDrive server starting
kDrive server initialization error: Unable to open parameters database.

after making these changes in the manifest:

  - --socket=x11
  - --socket=fallback-x11
  - --env=XDG_SESSION_TYPE=x11 # otherwise get errors relating to qt.qpa.plugin and qt.qpa.xcb
  - --env=QT_QPA_PLATFORM=xcb # otherwise get errors relating to qt.qpa.plugin and qt.qpa.xcb
  - --unset-env=WAYLAND_DISPLAY # otherwise get errors relating to qt.qpa.plugin and qt.qpa.xcb
  - --unset-env=SESSION_MANAGER # otherwise get "Qt Session management error: Could not open network socket"

Another comment. I have the “normal” AppImage version of kDrive running. I had a look in the logs and it referenced a few file paths:

New DB exists : /home/user/.config/kDrive/.parms.db => 1
Old config exists : /home/user/.config/kDrive/kDrive.cfg => 0
Adding extra plugin search path:/usr/lib/x86_64-linux-gnu/kDrive/plugins
Server started, listening at /run/user/1000/kDrive/socket

(btw the third one doesn’t actually exist)

Do I need to add anything to the manifest finish-args? I thought filesystem=home should be enough…

I made progress with my Flatpak by copying the sync-exclude.lst to the root of the appimage folder. I now manage to start kDrive but I get this error:

user@fedora:~/flatpak$ flatpak run com.infomaniak.kdrive
kDrive server starting

(process:3): GLib-GObject-CRITICAL **: 13:23:13.440: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed
/app/kdrive/usr/lib/libgnutls.so.30: version `GNUTLS_3_7_4' not found (required by /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so

(process:3): GLib-GObject-CRITICAL **: 13:23:13.440: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed

and the kDrive window just shows a message “This site can’t be reached” “ERR_CERT_AUTHORITY_INVALID” (I think it’s uses QtWebEngine or another webview implementation to get to the login page).

Any ideas how to fix it?

I think you should remove that lib from squashfs-root so that it’s picked up from runtime instead.
You can list the runtime libs this way:

ls /var/lib/flatpak/runtime/org.kde.Platform/x86_64/5.15-23.08/active/files/lib/x86_64-linux-gnu/

Best case you should remove all AppImage libs that are present in the runtime.

I see it’s based on Qt6 - it might be better to use a newer BaseApp.

I tried that by adding - rm squashfs-root/usr/lib/libgnutls.so.30 to the manifest built-commands, but it’s still the same error as before.

The KDE runtime seems to include a libgnutls.so.30 (the same file I’m deleting from the Appimage) as well as a libgio-2.0.so.0 but I don’t think there’s a libgiognutls.so that’s references in the error code.

The error still looks like this:

user@fedora:~/flatpak$ flatpak run com.infomaniak.kdrive
kDrive server starting

(process:3): GLib-GObject-CRITICAL **: 14:39:37.051: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed
/app/kdrive/usr/bin/../lib/libgnutls.so.30: version `GNUTLS_3_7_4' not found (required by /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so

(process:3): GLib-GObject-CRITICAL **: 14:39:37.052: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed

This is my current manifest:

app-id: com.infomaniak.kdrive

runtime: org.kde.Platform
runtime-version: 5.15-23.08
sdk: org.kde.Sdk

command: start-kdrive-flatpak.sh

finish-args:
  - --device=dri
  - --socket=x11 # if using wayland, even with fallback-x11, you get "could not connect to display" errors
  - --env=XDG_SESSION_TYPE=x11 # otherwise get "could not connect to display" errors
  - --env=QT_QPA_PLATFORM=xcb # otherwise get "could not connect to display" errors
  - --unset-env=WAYLAND_DISPLAY # otherwise get "could not connect to display" errors
  - --unset-env=SESSION_MANAGER # otherwise get "Qt Session management error Could not open network socket"
  - --share=network
  - --share=ipc
  - --filesystem=home
  - --talk-name=org.freedesktop.Notifications
  - --talk-name=org.freedesktop.secrets
  - --talk-name=org.kde.StatusNotifierWatcher
  - --talk-name=org.kde.kwalletd5

modules:
  - name: kdrive
    buildsystem: simple
    build-commands:
      # Extract the Appimage
     - chmod a+x kDrive.AppImage
     - ./kDrive.AppImage --appimage-extract >/dev/null
     - chmod -R --reference=kDrive.AppImage squashfs-root
     - rm ./kDrive.AppImage
     # Patch .desktop file with the new icon and binary location
     - sed -i -e 's/Icon.*/Icon=com.infomaniak.kdrive/' squashfs-root/kDrive_client.desktop
     - sed -i -e 's/Exec.*/Exec=start-kdrive-flatpak.sh %F/' squashfs-root/kDrive_client.desktop
     # Move things into place
     - cp squashfs-root/usr/bin/sync-exclude.lst squashfs-root/sync-exclude.lst # otherwise kDrive won't start
     - rm squashfs-root/usr/lib/libgnutls.so.30
     - mkdir /app/kdrive
     - cp -r squashfs-root/* /app/kdrive
     - install -Dm644 squashfs-root/kDrive_client.desktop /app/share/applications/com.infomaniak.kdrive.desktop
     - |
       for s in 16 32 48 64 128 256 512; do
         install -Dm644 squashfs-root/usr/share/icons/hicolor/${s}x${s}/apps/kdrive-win.png /app/share/icons/hicolor/${s}x${s}/apps/com.infomaniak.kdrive.png
       done
     - install -Dm644 com.infomaniak.kdrive.appdata.xml /app/share/appdata/com.infomaniak.kdrive.appdata.xml
     - install -Dm544 start-kdrive-flatpak.sh /app/bin/start-kdrive-flatpak.sh
    sources:
      - type: file
        url: https://download.storage.infomaniak.com/drive/desktopclient/kDrive-3.5.7.20240124-amd64.AppImage
        sha256: ab99aa9252d9e7c613d2a4247d368a6369926062b54ad7ddbb1ab36f1d591d4b
        only-arches:
         - x86_64
        dest-filename: kDrive.AppImage
      - type: file
        url: https://download.storage.infomaniak.com/drive/desktopclient/kDrive-3.5.7.20240124-arm64.AppImage
        sha256: 894f7544bfe302d747dd77d0769f69889e0bee6f1e6dbdce1c3410bd864519f3
        only-arches:
         - aarch64
        dest-filename: kDrive.AppImage
      - type: file
        path: com.infomaniak.kdrive.appdata.xml
      - type: script
        dest-filename: start-kdrive-flatpak.sh
        commands:
          - /app/kdrive/AppRun "$@"
# potentially add some kind of update checking here

I upgraded the BaseApp and Runtime to 6.6 but it’s still the same problem

edit: actually the error code has changed a bit:

flatpak run com.infomaniak.kdrive
kDrive server starting

(process:3): GLib-GObject-CRITICAL **: 15:04:01.501: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed
/usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so: undefined symbol: g_tls_channel_binding_error_quark
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so

(process:3): GLib-GObject-CRITICAL **: 15:04:01.501: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed


It’s from libgio-2.0.so.0. I think the runtime lib tries to read AppImage’s lib which is wrong

Interesting. The error goes away when I delete the libgio-2.0.so.0 from the AppImage, so that it uses the runtime one (presumably).

However it still can’t actually connect to the Internet:

Screenshot_20240208_154453

Here is the output of strace: user@fedora:~/flatpak$ strace flatpak run com.infomaniak.kdrive > kdrive-strace. - Pastebin.com

I killed the app through the task manager at the end.

Seems to work for me? (your manifest built, 6.6 base)

That’s so strange! I tried it on OpenSUSE and a Fedora VM. What’s your setup?

Ubuntu 22.04 with the latest updates

Very interesting. It does work in a Ubuntu 22.04 VM, for some reason.

However, when I actually try to log in, I get an error called “Token request failed: Failed to write authentification token into keychain” in the kDrive app. What could be the reason for this? Is - --talk-name=org.freedesktop.secrets not enough?

edit:
I tried adding some stuff copied from the Nextcloud YAML (because both Nextcloud and kDrive are forks of Owncloud):

modules:
  - shared-modules/libsecret/libsecret.json

  - name: qtkeychain
    buildsystem: cmake
    config-opts:
      - -DCMAKE_INSTALL_LIBDIR=lib
      - -DBUILD_TRANSLATIONS=NO
    cleanup:      
      - /include
      - /mkspecs
      - /lib/cmake
    sources:
      - type: archive
        url: https://github.com/frankosterfeld/qtkeychain/archive/0.14.2.tar.gz
        sha256: cf2e972b783ba66334a79a30f6b3a1ea794a1dc574d6c3bebae5ffd2f0399571
        x-checker-data:
          type: anitya
          url-template: https://github.com/frankosterfeld/qtkeychain/archive/$version.tar.gz
          stable-only: true
          project-id: 4138

But that doesn’t make any difference.

Ok, I figured it out. I needed at add --filesystem=xdg-run/keyring

Now it runs and syncs :slight_smile: Very good!

Although in my Ubuntu VM I can’t click on the tray icon, no idea if this is a Flatpak issue or GNOME issue.

edit: and I tried it in openSUSE Kalpa (KDE desktop) but the app doesn’t appear at all. No window, no tray icon. The console just says kDrive servers starting and then nothing.

Did you read through Desktop Integration - Flatpak documentation

So I tried adding all sorts of things but still it doesn’t work:

  - --talk-name=org.freedesktop.Notifications
  - --talk-name=org.freedesktop.secrets
  - --talk-name=org.kde.StatusNotifierWatcher
  - --talk-name=com.canonical.indicator.application
  - --talk-name=org.kde.kwalletd5
  - --filesystem=xdg-run/keyring
  - --own-name=org.kde.*