Init script for Gradle - Structure

Hello everyone.
Please, see this paste: What I'm trying to achieve - Pastebin.com
What I’m trying to achieve is to have compileSdkVersion and buildToolsVersion inside an init script, which I can run if needed.
But I don’t know where should I put the android section in the script.

Please, help.