Unable to add Firebase Crashlytics for Gradle version 7.2
Asked Answered
P

6

21

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.

Portable answered 8/6, 2022 at 8:4 Comment(0)
T
34

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'
}
Thinia answered 8/6, 2022 at 8:22 Comment(0)
P
38

Add this inside the root project's build.gradle file:

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 other plugins
}

Next, add this inside the app module's build.gradle file:

plugins {
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    .... some others plugins
}

Finally, add this inside the app module's build.gradle file:

dependencies {
    implementation platform('com.google.firebase:firebase-bom:30.3.1')
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    ... some other dependencies
}

Now, force a crash in your app something like this:

throw RuntimeException("Crashlytics Test")

Check your Firebase Console.

Done!

Prelusive answered 2/9, 2022 at 21:51 Comment(2)
Great, that was the answer I was looking for!Devoice
Actually, @Williaan, do you have a general instruction on how to go from "classpath" approach to the newer "plugins only" way? There a lots of integration instructions using the old way and I would use the new one everywhere to be consistent. For example, know I am trying to add OSS Licenses Gradle Plugin this way ( github.com/google/play-services-plugins/blob/master/… ) - any suggestions?Devoice
T
34

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'
}
Thinia answered 8/6, 2022 at 8:22 Comment(0)
P
8

You should use like this

   id 'com.google.firebase.crashlytics' version '2.9.2' apply false
Pascoe answered 23/11, 2022 at 7:19 Comment(2)
Where do you found it? I do not want to open a question for every plugin in my classpath.Repurchase
Thank you! Firebase should update their documentation on thisBarimah
O
5

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'
}
Outshoot answered 6/8, 2022 at 9:26 Comment(1)
This should accepted as the correct answer to work with gradle .kts fileIndigo
S
3

The easiest way is to let Android Studio add it for you.

Make sure you remove all code from previous attempts to add it and then:

Tools -> Firebase -> Crashlytics -> Get started with Firebase Crashlytics

There should be a button that will add the needed code.

Seldun answered 20/10, 2023 at 11:45 Comment(0)
D
0

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'
...
Devastation answered 8/2, 2023 at 16:10 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.