安装FCM会导致构建失败任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug

问题描述

一切正常,直到我安装了离子Cordova插件,然后添加cordova-plugin-fcm-with-dependecy-updated

Execution Failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
  Program type already present: android.support.v4.os.ResultReceiver$1
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

我正在尝试为离子应用程序设置推送通知,当我安装cordova FCM插件的那一刻,我得到了上述构建错误。我已经在网上尝试了一些建议,例如cordova clean,但这是行不通的。

ionic -v
6.0.1

cordova -v
9.0.0 (cordova-lib@9.0.1)


{
  "name": "","version": "0.0.1","author": "Ionic Framework","homepage": "https://ionicframework.com/","scripts": {
    "ng": "ng","start": "ng serve","build": "ng build","test": "ng test","lint": "ng lint","e2e": "ng e2e"
  },"private": true,"dependencies": {
    "@angular/common": "~9.1.6","@angular/core": "~9.1.6","@angular/forms": "~9.1.6","@angular/platform-browser": "~9.1.6","@angular/platform-browser-dynamic": "~9.1.6","@angular/router": "~9.1.6","@ionic-native/core": "^5.0.7","@ionic-native/image-picker": "^5.27.0","@ionic-native/ionic-webview": "^5.27.0","@ionic-native/splash-screen": "^5.0.0","@ionic-native/status-bar": "^5.0.0","@ionic/angular": "^5.0.0","@ionic/storage": "^2.3.0","angularfire2": "^5.4.2","cordova-plugin-device": "^2.0.2","cordova-plugin-fcm-with-dependecy-updated": "^7.2.0","cordova-plugin-ionic-keyboard": "^2.2.0","cordova-plugin-ionic-webview": "^4.2.1","cordova-plugin-splashscreen": "^5.0.2","cordova-plugin-statusbar": "^2.4.2","cordova-plugin-telerik-imagepicker": "^2.3.3","cordova-plugin-whitelist": "^1.3.3","firebase": "^7.17.1","moment": "^2.27.0","ngx-google-places-autocomplete": "^2.0.4","rxjs": "~6.5.1","tslib": "^1.10.0","zone.js": "~0.10.2"
  },"devDependencies": {
    "@angular-devkit/build-angular": "~0.901.5","@angular/cli": "~9.1.5","@angular/compiler": "~9.1.6","@angular/compiler-cli": "~9.1.6","@angular/language-service": "~9.1.6","@ionic/angular-toolkit": "^2.1.1","@types/node": "^12.11.1","@types/jasmine": "~3.5.0","@types/jasminewd2": "~2.0.3","codelyzer": "^5.1.2","jasmine-core": "~3.5.0","jasmine-spec-reporter": "~4.2.1","karma": "~5.0.0","karma-chrome-launcher": "~3.1.0","karma-coverage-istanbul-reporter": "~2.1.0","karma-jasmine": "~3.0.1","karma-jasmine-html-reporter": "^1.4.2","protractor": "~5.4.3","ts-node": "~8.3.0","tslint": "~6.1.0","typescript": "~3.8.3","cordova-plugin-whitelist": "1.3.3","cordova-plugin-statusbar": "2.4.2","cordova-plugin-device": "2.0.2","cordova-plugin-splashscreen": "5.0.2","cordova-plugin-ionic-webview": "^4.0.0","cordova-plugin-ionic-keyboard": "^2.0.5"
  },"description": "An Ionic project","cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},"cordova-plugin-statusbar": {},"cordova-plugin-device": {},"cordova-plugin-splashscreen": {},"cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },"cordova-plugin-ionic-keyboard": {},"cordova-plugin-telerik-imagepicker": {},"cordova-plugin-fcm-with-dependecy-updated": {
        "ANDROID_FCM_VERSION": "19.0.0","ANDROID_GRADLE_TOOLS_VERSION": "3.5.3","ANDROID_GOOGLE_SERVICES_VERSION": "4.3.3","ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher"
      }
    },"platforms": [
      "android","ios"
    ]
  }
}

解决方法

修复了以下问题: 离子cordova插件添加cordova-plugin-androidx 离子Cordova插件添加cordova-plugin-androidx-adapter 将这两行添加到platform / android / gradle.properties文件中

android.useAndroidX = true android.enableJetifier = true