如何将我的应用与 Firebase Crashlytics 集成?依赖问题

Posted

技术标签:

【中文标题】如何将我的应用与 Firebase Crashlytics 集成?依赖问题【英文标题】:How I can integrate my app with Firebase Crashlytics? Problems with dependencies 【发布时间】:2020-08-27 14:47:07 【问题描述】:

我的依赖项有问题,但我按照本指南做了所有事情。并尝试在 Gradle 应用文件中使用“exclude”和“useVersion”删除依赖项。

构建日志(您可以看到来自 firebase 和 google-play-services 库的重复类):

Duplicate class com.google.android.gms.measurement.AppMeasurement$ConditionalUserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.1)
Duplicate class com.google.android.gms.measurement.AppMeasurement$Event found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.1)
Duplicate class com.google.android.gms.measurement.AppMeasurement$EventInterceptor found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.1)
Duplicate class com.google.android.gms.measurement.AppMeasurement$OnEventListener found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.1)
Duplicate class com.google.android.gms.measurement.AppMeasurement$Param found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.1)
Duplicate class com.google.android.gms.measurement.AppMeasurement$UserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-impl-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-impl:17.4.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-api:17.4.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-api:17.4.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-api:17.4.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in modules jetified-firebase-analytics-impl-12.0.1-runtime.jar (com.google.firebase:firebase-analytics-impl:12.0.1) and jetified-play-services-measurement-api-17.4.1-runtime.jar (com.google.android.gms:play-services-measurement-api:17.4.1)

我的应用级 Gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'


android 
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig 
        applicationId "***"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    

   ...

    


    compileOptions 
        sourceCompatibility 1.8
        targetCompatibility 1.8
    

    kotlinOptions 
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    

    lintOptions 
        abortOnError false
    


...

dependencies 
    implementation fileTree(dir: "$rootDir/libs", include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.fragment:fragment-ktx:1.2.4'

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'org.osmdroid:osmdroid-android:6.1.6'
    implementation 'org.osmdroid:osmdroid-wms:6.1.6'
    implementation 'org.osmdroid:osmdroid-mapsforge:6.1.6'
    implementation 'org.osmdroid:osmdroid-geopackage:6.1.6'
    implementation 'org.osmdroid:osmdroid-third-party:6.0.1'
    implementation "androidx.preference:preference-ktx:1.1.1"
    //Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesLatestVersion"
    // Koin for Android
    implementation "org.koin:koin-android:$koinVersion"

    // Koin Android Scope features
    implementation "org.koin:koin-android-scope:$koinVersion"
    // Koin Android ViewModel features
    implementation "org.koin:koin-android-viewmodel:$koinVersion"
    // Koin Android Experimental features
    implementation "org.koin:koin-android-ext:$koinVersion"


    implementation project(path: ':data')
    implementation project(path: ':domain')
    implementation project(path: ':maplayoutlib')

    implementation 'com.annimon:stream:1.2.1'
    implementation 'com.google.android.material:material:1.1.0'

    implementation 'com.google.firebase:firebase-analytics:17.4.1'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0'

还有我的项目级 Gradle 文件:

buildscript 
    ext.kotlin_version = '1.3.72'
    ext.coroutinesLatestVersion = '1.3.3'
    ext.koinVersion = '2.1.5'

    repositories 
        google()
        jcenter()
        maven 
            url "https://jitpack.io"
        
    
    dependencies 
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0'
    


allprojects 
    repositories 
        google()
        jcenter()
    


task clean(type: Delete) 
    delete rootProject.buildDir


希望你能帮到我

编辑:

首先我有同样的依赖问题,添加时

implementation 'com.google.firebase:firebase-analytics:17.4.1'

apply plugin: 'com.google.gms.google-services'.

我使用v12.0.1解决了这个问题

resolutionStrategy.eachDependency  DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.google.android.gms') 
            details.useVersion '12.0.1'
        
        if (requested.group == 'com.google.firebase') 
            details.useVersion '12.0.1'
        
    

在我添加对 crashlytics 的依赖之前它正在工作

    apply plugin: 'com.google.firebase.crashlytics'
    ...

    implementation 'com.google.firebase:firebase-crashlytics:17.0.0'

你可以在上面看到这个版本的我的 gradle 文件

【问题讨论】:

给我看看你使用谷歌地图的maplayoutlib的依赖吧?它也应该是更新依赖项 我使用 osmdroid。我所有的地图依赖项都存在于应用程序级别的 Gradle 文件中。你可以看到他们。谢谢 【参考方案1】:

Firebase Crashlytics 应从您将其添加到项目的那一刻开始工作。不需要其他实现。 您的 gradle 文件对我来说看起来不错,但请尝试将应用级 Gradle 文件中的第一行更改为:

implementation fileTree(dir: 'libs', include: ['*.jar'])

并将项目级 Gradle 文件中的 crashlytics 依赖项更新到 v2.1.1

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.1'

【讨论】:

感谢您的回答。我在我的模块中使用 mavlink.jar。这就是为什么我用我的 mavlink.jar 替换 rootDir 中的 libs 文件夹的原因。我尝试使用不同的依赖库版本构建项目。我已经更改了 crashlytics 依赖项classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.0',但是对于重复的类,我得到了相同的结果。我不知道为什么

以上是关于如何将我的应用与 Firebase Crashlytics 集成?依赖问题的主要内容,如果未能解决你的问题,请参考以下文章

将我的 iOS 应用程序与 firebase 一起应用时出现错误

如何将 Flutter Web 与 Firebase 集成? [关闭]

Firebase - 如何访问已部署的应用程序

如何将我的 Firebase 实时数据库转移到 Firebase Cloud Firestore

如何将我的 Firebase 实时数据库转移到 Firebase Cloud Firestore

当我尝试将我的应用程序连接到 Firebase 身份验证时出现 MissingPluginException 异常