生成签名的 apk 时出错:com.google.gson.ExclusionStrategy 类型已定义多次

Posted

技术标签:

【中文标题】生成签名的 apk 时出错:com.google.gson.ExclusionStrategy 类型已定义多次【英文标题】:getting error on generating signed apk : Type com.google.gson.ExclusionStrategy is defined multiple times 【发布时间】:2021-02-28 10:59:21 【问题描述】:

当我生成签名的 apk 时,我收到了这个多重错误

com.google.gson.ExclusionStrategy 类型定义了多次

任务 ':app:mergeDexRelease' 的执行失败。 执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障 com.android.builder.dexing.DexArchiveMergerException:合并 dex 档案时出错: com.google.gson.ExclusionStrategy 类型定义了多次:D:\Irfan Android work2\Buzo New Project\Buzo New Project\Buzo Live Project\BUZO Live\wcs-android-sdk-1.1.0.13-release\build.transforms \9a323f6c9651ded54ae1a99d98f60ca1\jetified-wcs-android-sdk-1.1.0.13-release-runtime\classes.dex, D:\Irfan Android work2\Buzo New Project\Buzo New Project\Buzo Live Project\BUZO Live\app\build\intermediates \external_libs_dex\release\mergeExtDexRelease\classes2.dex

我的所有依赖项

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'commons-validator:commons-validator:1.6'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
implementation 'com.xw.repo:bubbleseekbar:3.20'
implementation 'android.arch.lifecycle:extensions:1.1.1'
api 'com.otaliastudios:cameraview:2.6.2'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'

// Retrofit & OkHttp
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.2'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
// Retrofit & OkHttp
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
implementation 'com.github.angads25:toggle:1.1.0'
implementation 'net.alhazmy13.MediaPicker:libary:2.4.4'
implementation 'com.danikula:videocache:2.7.1'
//implementation 'com.google.code.gson:gson:2.8.2'

//implementation 'com.github.bkhezry.android-image-picker:imagepicker:1.4.0'

implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'

annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//volley
implementation 'com.android.volley:volley:1.1.1'
//

implementation project(path: ':wcs-android-sdk-1.1.0.13-release')

implementation 'com.trafi:anchor-bottom-sheet-behavior:0.13-alpha'
//like
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
//
implementation 'com.github.f0ris.sweetalert:library:1.5.1'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
// FirebaseUI for Cloud Firestore

implementation 'gun0912.ted:tedpermission:2.2.3'
//country picker
implementation 'com.github.yesterselga:country-picker-android:1.0'
implementation 'com.github.florent37:viewanimator:1.1.0'


// Add the Firebase Crashlytics SDK.
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
//
//crop image
implementation platform('com.google.firebase:firebase-bom:26.0.0')
//firebase
implementation platform('com.google.firebase:firebase-bom:26.0.0')
implementation 'com.firebaseui:firebase-ui-firestore:6.3.0'
implementation 'androidx.paging:paging-runtime:2.1.2'
implementation 'com.google.firebase:firebase-auth:'
implementation 'com.google.firebase:firebase-database:'
implementation 'com.google.firebase:firebase-storage:'
implementation 'com.google.firebase:firebase-firestore:'
implementation 'com.google.firebase:firebase-messaging:'
implementation 'com.google.firebase:firebase-analytics:'
implementation 'com.firebaseui:firebase-ui-database:4.2.0'

implementation 'com.google.firebase:firebase-crashlytics-ndk:17.2.2'

implementation 'com.github.mike14u:croperino:1.1.8'

implementation 'com.iceteck.silicompressorr:silicompressor:2.2.4'
implementation 'com.github.smarteist:autoimageslider:1.3.2-appcompat'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.2'

【问题讨论】:

【参考方案1】:

在资源管理器中打开您的 android studio 项目。删除.gradle 文件夹。下一步是在 android studio 中清理你的项目,点击 Build->Clean Project。清理成功后,重建项目并重新运行。这应该可以解决您的问题。

【讨论】:

已经做了很多次了....但还是同样的问题....

以上是关于生成签名的 apk 时出错:com.google.gson.ExclusionStrategy 类型已定义多次的主要内容,如果未能解决你的问题,请参考以下文章

由于 proguard 规则,生成签名 APK 时出错

Retrofit 2.3.0 生成签名 APK 时出错

在 Android Studio 3 中激活 proguard 生成签名 Apk 时出错

膨胀类 com.google.android.exoplayer2.ui.SimpleExoPlayerView 时出错

androidstudio项目签名打包生成apk出错整理

添加“com.google.android.material:material:1.0.0-beta01”后,我们在创建签名 APK 时遇到了问题