The error message, Error: Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension, indicates that this plugin needs to be applied to a module which uses the com.android.application
plugin.
So, the simple solution is to only include the google-services plugin in your application module and not your library module:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…