Build android

Pulling in the patch from ivan-mogilko and some minor other fixes for building on Android.