This was a pain in the ass for me! Especially after updating to Android Studio 3.2.1 and Gradle 4.6 (for Gradle developers).
I think there is more than one factor that could cause such a build exception. For me, I had the following lines of code in my gradle.properties file (using SDK version 27):
android.useAndroidX=true
android.enableJetifier=true
AndroidX is the alternative to Android's default Support Library and should be used when compiling and targeting SDK version 28 (API 28). Before the updating Android Studio and Gradle, I had added the lines above in preparation to eventually fully migrate to AndroidX to use SDK version 28 and the build ran successfully. It was only after the update that I received an error similar to that above:
error: resource android:attr/fontVariationSettings not found
Hope this helps.