Running GTK4 tutorial code fails: Settings schema not installed

I’m at the section in the beginner tutorial where you use GSettings to save window size, but when I try to start my app, I get the following error:

(text-viewer:2): GLib-GIO-ERROR **: 02:07:58.392: Settings schema 'com.example.TextViewer' is not installed

I’m programming in Vala, using the default Meson build system. My build configuration is set to com.example.TextViewer.json, and my run command is set to the Flatpak Application option. My dependencies and SDKs are all updated, but if I try to run flatpak-builder manually, it doesn’t seem to be picking them up:

$ flatpak-builder --user --install --force-clean build-dir ./com.example.textViewer.json
error: org.gnome.Sdk/x86_64/master not installed
Failed to init: Unable to find sdk org.gnome.Sdk version master

I’d ideally like to run the app as a Flatpak so that it can be sandboxed and not mess up my system GSettings, put extra files in my build dir, require me to set up environment variables, etc. Any insight would be much appreciated, as I’m clearly still learning. :sweat_smile:

That’s because GNOME Builder has its own, internal installation where it installs the SDK to, which is not known to the stand-alone Flatpak Builder.
A bit annoying, I know…

As for your issue:
My guess is you either don’t install the GSettings schema file or there is some is mismatch. But hard to know without having a look at the schema file and the meson files.

Guess it’s there for convenience, as you can build a project with one click without adding flatpak remotes etc. Though, this can be changed as below:

  • Global (Preferences)
  • Per project (Configure Project)

Understood, here you go:

./com.example.textViewer.json
{
    "id" : "com.example.textViewer",
    "runtime" : "org.gnome.Sdk",
    "runtime-version" : "master",
    "sdk" : "org.gnome.Sdk",
    "sdk-extensions" : [
        "org.freedesktop.Sdk.Extension.vala"
    ],
    "command" : "text-viewer",
    "finish-args" : [
        "--share=network",
        "--share=ipc",
        "--socket=fallback-x11",
        "--device=dri",
        "--socket=wayland"
    ],
    "build-options" : {
        "append-path" : "/usr/lib/sdk/vala/bin",
        "prepend-ld-library-path" : "/usr/lib/sdk/vala/lib",
        "env" : {        }
    },
    "cleanup" : [
        "/include",
        "/lib/pkgconfig",
        "/man",
        "/share/doc",
        "/share/gtk-doc",
        "/share/man",
        "/share/pkgconfig",
        "/share/vala",
        "*.la",
        "*.a"
    ],
    "modules" : [
        {
            "name" : "text-viewer",
            "buildsystem" : "meson",
            "sources" : [
                {
                    "type" : "git",
                    "url" : "file:///home/nick/Projects"
                }
            ],
            "config-opts" : [
                "--libdir=lib"
            ]
        }
    ]
}
./meson.build
project('text-viewer', ['c', 'vala'],
          version: '0.1.0',
    meson_version: '>= 1.0.0',
  default_options: [ 'warning_level=2', 'werror=false', ],
)

i18n = import('i18n')
gnome = import('gnome')
valac = meson.get_compiler('vala')


srcdir = meson.project_source_root() / 'src'

config_h = configuration_data()
config_h.set_quoted('PACKAGE_VERSION', meson.project_version ())
config_h.set_quoted('GETTEXT_PACKAGE', 'text-viewer')
config_h.set_quoted('LOCALEDIR', get_option('prefix') / get_option('localedir'))
configure_file(output: 'config.h', configuration: config_h)

config_dep = valac.find_library ('config', dirs: srcdir)
config_inc = include_directories('.')

add_project_arguments('-DGETTEXT_PACKAGE="' + meson.project_name () + '"', language: 'c')


subdir('data')
subdir('src')
subdir('po')

gnome.post_install(
     glib_compile_schemas: true,
    gtk_update_icon_cache: true,
  update_desktop_database: true,
)
./src/meson.build
text_viewer_sources = [
  'main.vala',
  'application.vala',
  'window.vala',
]

text_viewer_deps = [
  config_dep,
  dependency('gtk4'),
  dependency('libadwaita-1', version: '>= 1.4'),
]

text_viewer_sources += gnome.compile_resources('text-viewer-resources',
  'text-viewer.gresource.xml',
  c_name: 'text_viewer'
)

executable('text-viewer', text_viewer_sources,
  dependencies: text_viewer_deps,
  include_directories: config_inc,
       install: true,
)
./data/meson.build
desktop_file = i18n.merge_file(
        input: 'com.example.textViewer.desktop.in',
       output: 'com.example.textViewer.desktop',
         type: 'desktop',
       po_dir: '../po',
      install: true,
  install_dir: get_option('datadir') / 'applications'
)

desktop_utils = find_program('desktop-file-validate', required: false)
if desktop_utils.found()
  test('Validate desktop file', desktop_utils, args: [desktop_file])
endif

appstream_file = i18n.merge_file(
        input: 'com.example.textViewer.metainfo.xml.in',
       output: 'com.example.textViewer.metainfo.xml',
       po_dir: '../po',
      install: true,
  install_dir: get_option('datadir') / 'metainfo'
)

appstreamcli = find_program('appstreamcli', required: false, disabler: true)
test('Validate appstream file', appstreamcli,
     args: ['validate', '--no-net', '--explain', appstream_file])

install_data('com.example.textViewer.gschema.xml',
  install_dir: get_option('datadir') / 'glib-2.0' / 'schemas'
)

compile_schemas = find_program('glib-compile-schemas', required: false, disabler: true)
test('Validate schema file',
     compile_schemas,
     args: ['--strict', '--dry-run', meson.current_source_dir()])


service_conf = configuration_data()
service_conf.set('bindir', get_option('prefix') / get_option('bindir'))
configure_file(
  input: 'com.example.textViewer.service.in',
  output: 'com.example.textViewer.service',
  configuration: service_conf,
  install_dir: get_option('datadir') / 'dbus-1' / 'services'
)

subdir('icons')
./data/com.example.textViewer.gschema.xml
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="text-viewer">
	<schema id="com.example.textViewer" path="/com/example/textViewer/">
	  <key name="window-width" type="i">
	    <default>600</default>
	  </key>
	  <key name="window-height" type="i">
	    <default>400</default>
	  </key>
	  <key name="window-maximized" type="b">
	    <default>false</default>
	  </key>
	</schema>
</schemalist>

Hopefully this should help. If you need anything else, just let me know.

Right, so in your GSettings schema file:

The id com.example.textViewer is not the exact same one as the one from the error message of your code (com.example.TextViewer).

Does it work if you change textViewer in your GSettings schema to TextViewer?

1 Like

What the hell, it does. Turns out it actually says to write it like that in the tutorial, as well! Thanks for helping me find that typo, haha.

Cannot find any such references. Can you clarify where it says so?

Or did you mean the tutorial was correct.

I meant the tutorial was correct and that I was mistaken. See here: Saving The Application State - GNOME Developer Documentation

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.