Build system cross-compile support and Android cross-compile

Follow up to #5242. All credit to @yichoi.