无法为 Gradle 版本 7.2 添加 Firebase Crashlytics

Amm*_*lah 18 android crashlytics android-gradle-plugin android-gradle-7.0

无法在 Android 中为 Gradle 7.2 添加 Firebase Crashlytics 依赖项/类路径

我应该写在哪里。

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
Run Code Online (Sandbox Code Playgroud)

我成功地将 Google 服务映射为。

    classpath 'com.google.gms:google-services:4.3.10'    
    //to
    id "com.google.gms.google-services" version "4.3.10" apply false
Run Code Online (Sandbox Code Playgroud)

如果我映射 Crashlytics 类路径,则会出现以下错误

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)
Run Code Online (Sandbox Code Playgroud)

项目级别 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 {

}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

设置.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'
Run Code Online (Sandbox Code Playgroud)

在发布这个问题之前我已经搜索了很多,但没有找到有用的东西。

Wil*_*pes 35

将其添加到根项目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 other plugins
}
Run Code Online (Sandbox Code Playgroud)

接下来,将其添加到应用程序模块build.gradle文件中:

plugins {
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    .... some others plugins
}
Run Code Online (Sandbox Code Playgroud)

最后,将其添加到应用程序模块build.gradle文件中:

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
}
Run Code Online (Sandbox Code Playgroud)

现在,强制您的应用程序崩溃,如下所示:

throw RuntimeException("Crashlytics Test")
Run Code Online (Sandbox Code Playgroud)

检查您的Firebase 控制台

完毕!


Mat*_*Pag 31

新的 Android 项目结构的文档尚未更新。

在您的项目级别中,build.gradle您需要添加以下内容:

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
}
Run Code Online (Sandbox Code Playgroud)

然后在您的应用程序级别build.gradle开始时您需要添加插件

plugins {
  id 'com.android.application'
  id 'org.jetbrains.kotlin.android'
  id 'com.google.firebase.crashlytics'
}
Run Code Online (Sandbox Code Playgroud)

然后在同一个文件中将 Crashlytics 依赖项添加到相应的块中:

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'
}
Run Code Online (Sandbox Code Playgroud)


小智 7

你应该这样使用

   id 'com.google.firebase.crashlytics' version '2.9.2' apply false
Run Code Online (Sandbox Code Playgroud)


小智 5

在项目的 build.gradle 中:

buildscript {
    ...
    ext.crashlytics_version = '2.9.1'
}

plugins {
    ...
    id 'com.google.firebase.crashlytics' version "$crashlytics_version" apply false
}
Run Code Online (Sandbox Code Playgroud)

然后在应用程序的 build.gradle 中应用该插件:

plugins {
    ...
    id 'com.google.firebase.crashlytics'
}
Run Code Online (Sandbox Code Playgroud)