UnknownPluginException using Google Play Services and Plugins DSL - android

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.

Adding the google-services plugin to the plugins {} block is causing errors. The alternate way that I've found is:
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'
}
}
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 :)

By using Android Studio Bumblebee new Groovy DSL plugin management Add below line in build.gradle(Project:) plugins{} section and sync project will solve your problem.
id 'com.google.gms.google-services' version '4.3.10' apply false
your build.gradle(Project:) looks like
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.dagger.hilt.android' version '2.41' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false
id 'com.google.firebase.crashlytics' version '2.8.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
your build.gradle(Module:) looks like
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id 'com.google.dagger.hilt.android'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
android {
compileSdk 32
signingConfigs {
config {
enableV3Signing true
enableV4Signing true
}
}
}
your settings.gradle(Project Settings) looks like
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyApp"
include ':app'

Related

How to add Crashlytics to the new architecture sample by Google

I am starting a new project by using the architecture-templates by google (https://github.com/android/architecture-templates)
In this template, they use Gradle with Kotlin DSL. I am trying to add Crashlytics to this project but the structure of gradle is quite different from my old projects.
I am stuck on the step 2 of the base guide (Firebase Get Started Documentation)
Error resolving plugin [id: 'com.android.application', version:
'7.3.1']
The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so
compatibility cannot be checked.
Any suggestion?
After some research I found that the architecture template is based on gradle 7.6 which use the version catalog feature.
So I based my Version Catalog file on this https://github.com/RedMadRobot/gradle-version-catalogs/blob/main/versions-stack/libs.versions.toml
Now my build.gradle.kts file is
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.hilt.gradle)
alias(libs.plugins.firebase.crashlitycs)
alias(libs.plugins.gms.googleServices)
}
....
dependencies {
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.crashlytics)
implementation(libs.firebase.analytics)
}
I used to be confused about this too, but after some tries, I found the correct answer.
I think this is the first point of step 2 where you are confused. Just add the following code at the top of the project level build.gradle:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
}
}
Just follow the Google guide for the rest.
Complete code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Edited:
DSL version:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath("com.google.gms:google-services:4.3.14")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.2")
}
}
plugins {
id("com.android.application") version "7.2.2" apply false
id("com.android.library") version "7.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.7.10" apply false
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
This website(Gradle Kotlinize - Groovy to Kotlin converter online) may be able to help you.

android studio gradle plugin problems out of the box

just installed android studio after getting a fresh install of win10. i created a new empety project and got this error:
Gradle sync failed: Plugin [id: 'com.android.application', version:
'7.2.1', apply: false] was not found in any of the following sources:
this is the code:
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
Edit: the sources were blank and the path to the file is C:\Users\RK33DV\AndroidStudioProjects\test\build.gradle
The problem is you're missing settings.gradle file. Try to add settings.gradle file to your project root directory with the following content:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "projectName"
include ':app'

Latest Android Studio - Problem adding Google Service Gradle plugin to build.gradle file

I am having trouble adding Google Service Gradle plugin to build.gradle file in latest Android Studio Chipmunk. Specifically I am trying to add classpath 'com.google.gms:google-services:4.3.12'.
It seems project level build.gradle file has changed from previous versions. I don't know where to add the above dependency. Any help would be highly appreciated. Thanks.
paste code for your build-script class file in project-level gradle.build file, here is an example :
/**
* project-level - build.gradle file -- make sure buildscript is before
* plugins
**/
buildscript {
repositories {
mavenCentral()
}
dependencies {
// your classpath
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.41'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.20' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Examples from my projects.
Project level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}
Or module level build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}

Unable to add Firebase Crashlytics for Gradle version 7.2

Unable to add Firebase Crashlytics dependencies/classpath in Android for Gradle 7.2
Where should I write.
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
I successfully mapped Google services as.
classpath 'com.google.gms:google-services:4.3.10'
//to
id "com.google.gms.google-services" version "4.3.10" apply false
Getting following error if I map Crashlytics classpath
Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.firebase.firebase-crashlytics-gradle', version: '2.9.0', apply: false] 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.firebase.firebase-crashlytics-gradle:com.google.firebase.firebase-crashlytics-gradle.gradle.plugin:2.9.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo
BintrayJCenter
maven(https://jitpack.io)
Project level Gradle
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.30' apply false
id "com.google.gms.google-services" version "4.3.10" apply false
// below line has a problem
id 'com.google.firebase.firebase-crashlytics-gradle' version '2.9.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
}
Gradle-wrapper.properties
#Thu May 12 10:12:33 PKT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "Video Player"
include ':app'
I had searched a lot before posting this question but didn't find something useful.
The documentation is not updated for the new Android project structure yet.
In your project level build.gradle you need to add this:
buildscript {
//other things....
dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.20' apply false
id "com.google.gms.google-services" version "4.3.10" apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Then in your app level build.gradle at the start you need to add the plugin
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.firebase.crashlytics'
}
and then in the same file add the Crashlytics dependencies to the corresponding block:
dependencies {
//... other dependencies
implementation platform('com.google.firebase:firebase-bom:30.1.0')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
}
Add this inside Root project build.gradle
plugins {
id 'com.google.gms.google-services' version '4.3.10' apply false
id 'com.google.firebase.crashlytics' version '2.9.1' apply false
.... some others classpath
}
And this inside the App Module build.gradle
plugins {
.... some others plugins
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
And finally...
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
So force a crash in your code, something like this
throw RuntimeException("Crashlytics Test")
Now check your Firebase Console
Done!
In your project's build.gradle:
buildscript {
...
ext.crashlytics_version = '2.9.1'
}
plugins {
...
id 'com.google.firebase.crashlytics' version "$crashlytics_version" apply false
}
Then in your app's build.gradle, apply the plugin:
plugins {
...
id 'com.google.firebase.crashlytics'
}
You should use like this
id 'com.google.firebase.crashlytics' version '2.9.2' apply false
Use the Kotlin libraries, even if you're on Java:
...
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
...

build.gradle (project) completely different?

I setup a new (Kotlin) project using Android Studio. When I take a look at my build.gradle (Project), I see this content:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
However, other build.gradles seem to be completely different.
I searched all files, but couldn't find any occurrences of the buildscript, dependencies or any other block.
Where are they or how do I add them?
buildscript was used to add the version of dependencies and classpaths. In the newer versions of android studio you have to mention the version directly after the dependency implementations.
So for example, I wanted to add the classpath "androidx.navigation:navigation-safe-args-gradle-plugin" to my build.gradle(Project) for the plugin id "androidx.navigation.safeargs.kotlin" , but in the newer version it has been moved to settings.gradle and is done by adding a resolutionStrategy block just after the repositories block: -
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'androidx.navigation.safeargs.kotlin') {
useModule("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2")
}
}
}
}
after that, you can add the plugin id "androidx.navigation.safeargs.kotlin" in plugin block in the build.gradle(Module) and sync it: -
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}
Hope this is helpful!!
There are two build.gradle files in android studio i.e. build.gradle(Project) & build.gradle(Module).
Required blocks like buildscript, dependencies are available in build.gradle(Module)
build.gradle(Module) looks like:
Hope this will help :)
Repositories have been moved to settings.gradle and module Gradle has been moved to the app package gradle.

Categories

Resources