I had a similar problem where most of the Build menu items were greyed out.

‘Sync project with Gradle files’ didn’t fix.
I noticed a ‘Build Variants’ toggle button on the bottom left of Android Studio (v 3.1.2) and with this was finally able to choose the variant I needed.

Maybe this will work for you too.