Keyboard layout not working in Ubuntu 18.04

Just for information, if someone is in a similar situation and wants to avoid restarting, this worked for me. TL;DR:

sudo dpkg-reconfigure keyboard-configuration
gsettings reset org.gnome.desktop.input-sources xkb-options

Reloading Gnome after changing the keyboard language also works, which is less "destructive" than than logging out or restarting:

ALT + F2 to bring up the command box, r and Enter to reload.


The solution was - restarting the system.