You're missing the google maven repo in your allprojects block:
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
If you're using Gradle 4.1 or later, you can simplify it:
allprojects {
repositories {
jcenter()
google()
}
}
allprojects repositories is what's used to locate modules for your app. In buildscript, it locates modules for gradle plugins only.
Also, you should make sure all of your Firebase modules have the same version.