Home > Software engineering >  How to add Crashlytics to the new architecture sample by Google
How to add Crashlytics to the new architecture sample by Google

Time:01-11

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 stucked 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?

CodePudding user response:

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
}

CodePudding user response:

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)
}
  • Related