import java.util.regex.Pattern def doExtractStringFromManifest(name) { def manifestFile = file(android.sourceSets.main.manifest.srcFile) def pattern = Pattern.compile(name + "=\"(.*?)\"") def matcher = pattern.matcher(manifestFile.getText()) matcher.find() return matcher.group(1) } android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' } } defaultConfig { multiDexEnabled true applicationId = doExtractStringFromManifest("package") } } buildscript { repositories { jcenter() mavenLocal() } dependencies { classpath 'com.android.tools.build:gradle:+' classpath 'com.google.gms:google-services:3.0.0' } } // apply plugin: 'com.google.gms.google-services' // class must be used instead of id(string) to be able to apply plugin from non-root gradle file ext.postBuildExtras = { apply plugin: com.google.gms.googleservices.GoogleServicesPlugin }