如何将firebase crashlytics添加到android项目中

loading...


0

在我的应用程序中,我想使用 firebase Crashlytics ,为此,我将以下代码添加到我的应用程序中 .
我从google文档中逐步添加了此代码!
我添加了以下代码但是当同步应用程序显示错误而不同步项目时 .

Build.gradle (project) :

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
        classpath 'io.fabric.tools:gradle:1.26.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url 'https://dl.bintray.com/tapsellorg/maven' }
        maven { url 'https://maven.google.com/' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Build.gradle (app) :

dependencies {
    implementation 'com.google.android.gms:play-services-base:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

但添加此行 apply plugin: 'com.google.gms.google-services' 时,点击同步时显示以下错误:

The library com.google.android.gms:play-services-base is being requested by various other libraries at [[11.0.2,11.0.2]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

我该如何解决?

loading...

1回答

  • 0

    您不需要任何依赖or.jar文件来在您的应用中添加crashlytics,只需按照以下步骤操作即可告诉我您是否遇到任何错误 . 将Google Analytics for Firebase的依赖关系添加到您的应用级build.gradle文件:

    implementation 'com.google.firebase:firebase-core:16.0.6'
    

    在此之后,声明活动顶部的com.google.firebase.analytics.FirebaseAnalytics对象:

    private FirebaseAnalytics mFirebaseAnalytics;
    

    然后在onCreate()方法中初始化它:

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    

    这是有关更多信息,请参阅Firebase的官方文档,了解如何集成crashlytics(https://firebase.google.com/docs/analytics/android/start

    注意:firebase库的不匹配可能会导致gradle编译错误

评论

暂时没有评论!