I go to
build.gradle and click sync now. Then it worked.
Sync Project with Gradle Files (Android Studio 3.1.1)
Sync Project with Gradle Files (Android Studio 3.0.1)
Or You can click on the icon from the toolbar.
This answer may not help works for later version as Android studio Team work on making the tool more better, the way to sync may be different in the next version of Android Studio.
COMMON WAY that may helps is try to sync project and then Invalidate Caches and Restart Android Studio.
Android Studio 3.1.2 [See below answer]