Android Studio Gradle Error at Compile Time
This is what worked for me:
Android Studio -> File -> Invalidate Caches and Restart
1.delete {project dir}/.gradle/{gradle distribution version dir}
{gradle distribution version dir} is whatever the gradle distribution version you use (ref: https://developer.android.com/studio/releases/gradle-plugin.html#revisions). For example, it can be "1.9" or "2.10" or some other version number.
2.Sync Project with Gradle File