You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ionic项目构建报错:Google ZXing相关类重复冲突

解决Ionic项目构建中的重复类错误

问题描述

构建Ionic项目时出现重复类错误,具体错误信息如下:

Duplicate class com.google.zxing.qrcode.encoder.Encoder$1 found in modules jetified-barcodescanner-release-2.1.5-runtime (:barcodescanner-release-2.1.5:) and jetified-core-3.4.0 (com.google.zxing:core:3.4.0)
Duplicate class com.google.zxing.qrcode.encoder.MaskUtil found in modules jetified-barcodescanner-release-2.1.5-runtime (:barcodescanner-release-2.1.5:) and jetified-core-3.4.0 (com.google.zxing:core:3.4.0)
Duplicate class com.google.zxing.qrcode.encoder.MatrixUtil found in modules jetified-barcodescanner-release-2.1.5-runtime (:barcodescanner-release-2.1.5:) and jetified-core-3.4.0 (com.google.zxing:core:3.4.0)
Duplicate class com.google.zxing.qrcode.encoder.QRCode found in modules jetified-barcodescanner-release-2.1.5-runtime (:barcodescanner-release-2.1.5:) and jetified-core-3.4.0 (com.google.zxing:core:3.4.0)

中文翻译

在模块jetified-barcodescanner-release-2.1.5-runtime(:barcodescanner-release-2.1.5:)和jetified-core-3.4.0(com.google.zxing:core:3.4.0)中发现重复类com.google.zxing.qrcode.encoder.Encoder$1
在模块jetified-barcodescanner-release-2.1.5-runtime(:barcodescanner-release-2.1.5:)和jetified-core-3.4.0(com.google.zxing:core:3.4.0)中发现重复类com.google.zxing.qrcode.encoder.MaskUtil
在模块jetified-barcodescanner-release-2.1.5-runtime(:barcodescanner-release-2.1.5:)和jetified-core-3.4.0(com.google.zxing:core:3.4.0)中发现重复类com.google.zxing.qrcode.encoder.MatrixUtil
在模块jetified-barcodescanner-release-2.1.5-runtime(:barcodescanner-release-2.1.5:)和jetified-core-3.4.0(com.google.zxing:core:3.4.0)中发现重复类com.google.zxing.qrcode.encoder.QRCode

解决方案

这个问题是因为项目同时引入了barcodescanner插件和com.google.zxing:core依赖,两者包含相同的Zxing编码类,导致冲突,可通过以下方法解决:

  • 排除重复依赖:在项目的build.gradle文件中,给barcodescanner依赖添加排除规则,移除其自带的Zxing核心模块,保留单独引入的com.google.zxing:core:
dependencies {
    // 其他依赖...
    implementation('com.google.zxing:core:3.4.0')
    implementation(':barcodescanner-release-2.1.5:') {
        exclude group: 'com.google.zxing', module: 'core'
    }
}
  • 统一依赖版本:如果不需要单独引入com.google.zxing:core,直接移除该依赖,使用barcodescanner插件自带的版本即可。

  • 更新插件版本:尝试更新barcodescanner插件到最新版,新版本可能已修复依赖冲突问题,执行以下命令更新:

ionic cordova plugin update phonegap-plugin-barcodescanner
npm update @ionic-native/barcode-scanner

内容的提问来源于stack exchange,提问作者Ahmadou Adiawiakoye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 14:21:31