make sure you use default gradle wrapper.
Open File > Settings (or Android Studio > Preferences... on Mac), in the dialog navigate to Build,Execution,Deployment > Build Tools > Gradle.
then click use default gradle wrapper (recommended) and uncheck offline work.