I got this error when I used the automatic creation of Activity in Studio. Apparently, studio tried to add ConstraintLayout dependency to my build.gradle file and this messed up my build.gradle file.
If this is the case, just use your version control and see what's messed up and correct it.