Android virtual keyboard app that support physical keyboard language and layout change
The following software have independent physical keyboard layouts not tied to the OS layout in any way.

ruKeyboard software. It's a software+hardware keyboard initially made for Android smartphones with qwerty keyboard. It supports Android 2.3-9 and allows to add your own software and hardware layouts for different languages (you need to modify the XML files inside apk, but it's not that hard). It's abandoned and not open source, but still works fine. Software and physical keyboard layout switching is independent. You can configure your own switching combination on physical keyboard.

AnySoftKeyboard is what you can call a modern alternative to ruKeyboard. It's a software keyboard with support for physical keyboards. You can define your own layouts just as in ruKeyboard, by editing xml files inside the apk. Layout swithing is unified: if you switch the layout on software keyboard, it would switch on hardware keyboard as well. It's open source.