There are three ways to remap keys:
- Directly install keylayout (*.kl) and/or charmap (*.kcm) files. This requires root or Magisk.
- Install an app that uses android.hardware.input.metadata.KEYBOARD_LAYOUTS metadata to supply additional (fixed) keyboard layouts.
- Install an app that allows users to customize the keyboard layout on an adhoc basis.
I have done the first two methods, but I have no experience with the third and don't know whether it still works on current systems.