【问题标题】:ionic 4 cordova android build error - transformDexArchiveWithExternalLibsDexMergerForDebugionic 4 cordova android 构建错误-transformDexArchiveWithExternalLibsDexMergerForDebug
【发布时间】:2020-05-02 06:43:16
【问题描述】:

我正在尝试构建 Android 应用并收到此输出错误:

BUILD FAILED in 39s
/Users/myuser/dev/myapp/platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D8: Program type already present: com.google.zxing.BarcodeFormat

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
  Program type already present: com.google.zxing.BarcodeFormat
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

我根据互联网搜索结果尝试的事情:

  • cordova clean + cordova build
  • 删除android平台并重新添加
  • 在另一个地方克隆存储库并从头开始构建它

所以同样的错误不断发生。

这是我的package.json 文件供参考:

{
  "name": "myapp",
  "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": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@ionic-native/app-rate": "^5.19.0",
    "@ionic-native/app-version": "^5.17.1",
    "@ionic-native/badge": "^5.17.1",
    "@ionic-native/barcode-scanner": "^5.17.1",
    "@ionic-native/call-number": "^5.19.1",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/device": "^5.17.1",
    "@ionic-native/diagnostic": "^5.17.1",
    "@ionic-native/facebook": "^5.19.1",
    "@ionic-native/firebase": "^5.18.0",
    "@ionic-native/firebase-x": "^5.18.0",
    "@ionic-native/geolocation": "^5.17.1",
    "@ionic-native/google-maps": "^5.0.0-beta.27",
    "@ionic-native/keyboard": "^5.19.1",
    "@ionic-native/launch-navigator": "^5.19.1",
    "@ionic-native/network": "^5.17.1",
    "@ionic-native/screen-orientation": "^5.17.1",
    "@ionic-native/splash-screen": "^5.17.1",
    "@ionic-native/status-bar": "^5.17.1",
    "@ionic-native/unique-device-id": "^5.19.0",
    "@ionic/angular": "^4.7.1",
    "@ionic/storage": "^2.2.0",
    "call-number": "^1.0.1",
    "cordova-android": "^8.1.0",
    "cordova-android-support-gradle-release": "^3.0.1",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-androidx": "^1.0.2",
    "cordova-plugin-androidx-adapter": "^1.1.0",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-apprate": "^1.5.0",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-dialogs": "^2.0.2",
    "cordova-plugin-facebook4": "^6.2.0",
    "cordova-plugin-firebase": "^2.0.5",
    "cordova-plugin-firebasex": "^7.0.1",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-googlemaps": "^2.6.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.1.3",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-screen-orientation": "^3.0.2",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "~2.4.2",
    "cordova-plugin-uniquedeviceid": "^1.3.2",
    "cordova-plugin-whitelist": "~1.3.3",
    "cordova-support-android-plugin": "^1.0.1",
    "cordova-support-google-services": "^1.3.2",
    "cordova.plugins.diagnostic": "^5.0.1",
    "core-js": "^2.5.4",
    "es6-promise-plugin": "^4.2.2",
    "ionicons": "git://github.com/ionic-team/ionicons.git#3.0",
    "ios-sim": "^8.0.2",
    "mx.ferreyra.callnumber": "0.0.2",
    "ngx-mask-ionic": "^1.1.2",
    "phonegap-plugin-barcodescanner": "^8.1.0",
    "rxjs": "~6.5.1",
    "rxjs-compat": "^6.5.3",
    "tslib": "^1.9.0",
    "uk.co.workingedge.phonegap.plugin.launchnavigator": "^5.0.4",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.801.2",
    "@angular-devkit/build-angular": "~0.801.2",
    "@angular-devkit/core": "~8.1.2",
    "@angular-devkit/schematics": "~8.1.2",
    "@angular/cli": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@ionic/angular-toolkit": "^2.1.1",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-app-version": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-screen-orientation": {},
      "cordova-plugin-geolocation": {},
      "cordova.plugins.diagnostic": {
        "ANDROID_SUPPORT_VERSION": "28.+"
      },
      "cordova-plugin-badge": {},
      "phonegap-plugin-barcodescanner": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-firebasex": {
        "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true",
        "FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "true",
        "FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "true",
        "ANDROID_ICON_ACCENT": "#FF00FFFF",
        "ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION": "17.0.0",
        "ANDROID_FIREBASE_ANALYTICS_VERSION": "17.2.1",
        "ANDROID_FIREBASE_MESSAGING_VERSION": "20.0.0",
        "ANDROID_FIREBASE_CONFIG_VERSION": "19.0.3",
        "ANDROID_FIREBASE_PERF_VERSION": "19.0.1",
        "ANDROID_FIREBASE_AUTH_VERSION": "19.1.0",
        "ANDROID_CRASHLYTICS_VERSION": "2.10.1",
        "ANDROID_CRASHLYTICS_NDK_VERSION": "2.1.1"
      },
      "cordova-plugin-androidx-adapter": {},
      "cordova-plugin-uniquedeviceid": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-apprate": {},
      "uk.co.workingedge.phonegap.plugin.launchnavigator": {
        "GOOGLE_API_KEY_FOR_ANDROID": "AIzaSyDb5ggUt5U1vXF2RSVHvtecnX-xv36Lays",
        "OKHTTP_VERSION": "3.12.0",
        "LOCATION_USAGE_DESCRIPTION": "Veja estabelecimentos mais próximos de você com dinheiro de volta"
      },
      "mx.ferreyra.callnumber": {},
      "cordova-plugin-googlemaps": {
        "API_KEY_FOR_ANDROID": "AIzaSyDb5ggUt5U1vXF2RSVHvtecnX-xv36Lays",
        "API_KEY_FOR_IOS": "AIzaSyDb5ggUt5U1vXF2RSVHvtecnX-xv36Lays",
        "PLAY_SERVICES_VERSION": "15.0.1",
        "ANDROID_SUPPORT_V4_VERSION": "27.+",
        "LOCATION_WHEN_IN_USE_DESCRIPTION": "Somente utilizamos a sua localização quando o app estiver aberto",
        "LOCATION_ALWAYS_USAGE_DESCRIPTION": "This app wants to get your location always, even this app runs in background."
      },
      "call-number": {},
      "cordova-plugin-facebook4": {
        "APP_ID": "573564436804950",
        "APP_NAME": "myapp",
        "FACEBOOK_HYBRID_APP_EVENTS": "true",
        "FACEBOOK_ANDROID_SDK_VERSION": "5.5.2"
      },
      "cordova-plugin-androidx": {},
      "cordova-plugin-compat": {},
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "27.+"
      }
    },
    "platforms": [
      "android"
    ]
  }
}

可能的冲突插件(来自我的 package.json)

一些答案​​讲述了管理 android/firebase 版本的冲突插件。那么也许使用所有这些库/插件可能是问题所在?

npm

  • @ionic-native/firebase-x
  • cordova-android-support-gradle-release
  • cordova-plugin-androidx
  • cordova-plugin-androidx-适配器
  • cordova-plugin-firebasex
  • cordova-support-android-plugin

cordova 插件

  • cordova-plugin-firebasex
  • cordova-plugin-androidx-适配器
  • cordova-plugin-androidx
  • cordova-plugin-compat
  • cordova-android-support-gradle-release

我还能尝试什么来解决这个问题?在这个问题上花了2天时间:(

【问题讨论】:

    标签: android cordova ionic-framework


    【解决方案1】:

    你可以试试这个步骤

    cd platforms/android
    gradlew clean
    cd ..
    cd ..
    ionic cordova build android --prod --release
    

    【讨论】:

    • 同样的错误但另一个类:Program type already present: com.google.zxing.Binarizer
    • 尝试删除android平台然后运行构建代码(ionic cordova build android --prod --release)
    • 我有同样的问题,尝试了很多东西,尝试你的解决方案然后 gradlew' 不被识别为 cmdlet 的名称
    • 运行 'gradle -v' @GaliloGalilo 后你能看到结果吗
    • 我正在研究 ionic(我不使用 gradle),但通过一个一个更新所有插件,然后是最小 sdk 来解决。谢谢你
    猜你喜欢
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 2018-04-18
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多