Support for Android Studio 1.0 with newer gradle and build tools

New PR from a branch that shouldn't see other changes.