Home > database >  UnknownPluginException using Google Play Services and Plugins DSL
UnknownPluginException using Google Play Services and Plugins DSL

Time:10-26

I'm creating a new application in Android Studio Bumblebee and this defaults to using the new Groovy DSL plugin management in settings.gradle.

I need to be able to use Google Play Services to enable Firebase functionality, however I am running into a build error when applying the com.google.gms.google-play-services plugin using the documentation here: Google Play Services Readme

I have added the following to my settings.gradle file:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
    }
    plugins {
        id 'com.android.application' version '7.1.0-alpha13'
        id 'com.android.library' version '7.1.0-alpha13'
        id 'org.jetbrains.kotlin.android' version '1.5.31'
        id 'com.google.gms.google-services' version '4.3.10'
    }
}

and the following to my app's build.gradle file:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}

however when I build the application, I get the following UnknownPluginException:

Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google

I have also tried the legacy method of classpath etc. but this results in a much longer error message regarding dependency resolution.

I'm not sure what I am doing wrong.

CodePudding user response:

Adding the google-servies plugin to the plugins {} block is causing errors. The alternate way that I've found is:

  1. First, in your root build file (not the one in the app folder), inside the buildscript {} block, add this
buildscript {
 repositories {
   google()
   mavenCentral()
 }
 dependencies {
   classpath 'com.google.gms:google-services:4.3.10'
 }
}
  1. In the build file in the app folder, apply the plugin like this,
apply plugin: 'com.google.gms.google-services'

In step 1, using mavenCentral() is necessary as the google-services plugin downloads the linked dependencies like gson from maven central :)

  • Related