程序类型已经存在:android.support.v4.os.ResultReceiver$MyResultReceiver在Ionic上。

9
我正在使用 Ionic 构建应用程序,并添加了 Firebase Cloud Message 功能,一切都运行得很好。但是今天,当我构建时出现了错误。
尝试执行以下操作:
  1. ionic cordova platform rm android
  2. 移除插件
  3. 清除缓存
  4. 删除 package-lock.js
  5. npm i 6 ionic cordova platform add android 7 ionic cordova prepare 8 ionic cordova build android
错误信息如下所示:

Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED 37 actionable tasks: 7 executed, 30 up-to-date D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

构建失败,并且出现以下异常信息:
  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获取更多日志输出。使用 --scan 运行以获得完整的信息。

  • 获取更多帮助,请访问 https://help.gradle.org

构建失败,出现异常信息如下所示:
  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

1个回答

64

我遇到了相同的问题,后来发现是因为 Firebase 和 GooglePlus 插件。最终,我找到了一个对我有用的解决方案:

ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

仅仅添加这些插件就解决了所有编译错误。


4
不用谢 :) 如果有人仍然遇到Firebase插件问题,可以使用修复过的分支之一,例如https://github.com/wizpanda/cordova-plugin-firebase-lib或https://github.com/dpa99c/cordova-plugin-firebase。在重新构建之前,考虑使用“cordova clean android”命令以获得干净的状态。 - Jeremy Belolo
如果有人偶然来到这里,Firebase插件社区开发者现在常用的fork是https://github.com/dpa99c/cordova-plugin-firebase。 - Jeremy Belolo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接