How to fix this error duplicate class found in module class.jar

匆匆过客 提交于 2020-01-14 13:04:55

问题


I got this error when I try to generate signed apk for my project

Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:16.5.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules classes.jar (com.google.android.gms:play-services-measurement-api:16.5.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event found in modules classes.jar (com.google.android.gms:play-services-measurement-api:16.5.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param found in modules classes.jar (com.google.android.gms:play-services-measurement-api:16.5.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1) Duplicate class com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-api:16.5.0) and classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)

Go to the documentation to learn how to Fix dependency resolution errors.

how do I fix It?


回答1:


Try with

implementation("com.google.android.gms:play-services-gcm:$project.playServicesVersion") {
    exclude group: 'com.google.android.gms'
}

You can Try including one by one the one which brings errors you apply

 implementation("**API**") {
    exclude group: 'com.google.android.gms'
}

NB $project.playServicesVersion could be any of your versions you are using




回答2:


For those who face this type of issue in the future

Ensure that you are using the specific dependency of play services according to your requirements. In my case, I need a map dependency but I am importing the play service dependency which causes duplicate class issues with another firebase dependency.

Use this

def playServiceVersion = "17.0.0"
implementation "com.google.android.gms:play-services-maps:$playServiceVersion"

Instead of

def playServiceVersion = "17.0.0"
implementation "com.google.android.gms:play-services:$playServiceVersion"

For further information check the link below

https://developers.google.com/android/guides/setup



来源:https://stackoverflow.com/questions/56089509/how-to-fix-this-error-duplicate-class-found-in-module-class-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!