For me what worked is the following:
sudo xcode-select --reset
Then like in @High6's answer:
sudo xcodebuild -license
This will reveal a license which I assume is some Xcode license. Scroll to the bottom using space (or the mouse) then tap agree
.
This is what worked for me on MacOS Mojave v 10.14.