添加zxing依赖出现冲突错误,无法构建Kotlin二维码应用
问题根源
你遇到的是依赖重复类冲突:com.journeyapps:zxing-android-embedded:3.6.0这个库内部已经默认依赖了zxing-core,你手动添加的com.google.zxing:core:3.4.1和它内置的core库版本重复,导致构建时出现Duplicate class com.google.zxing.Result错误。
解决方案
直接移除手动添加的com.google.zxing:core:3.4.1依赖即可,因为zxing-android-embedded已经包含了生成二维码所需的核心类。修改后的build.gradle依赖配置如下:
dependencies { implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.8.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation 'com.github.yuriy-budiyev:code-scanner:2.3.2' //for scanning qr implementation 'com.journeyapps:zxing-android-embedded:3.6.0' }
额外说明
你的二维码生成代码不需要任何修改——zxing-android-embedded已经包含了QRCodeWriter、BarcodeEncoder等核心类,原有的导入语句和逻辑都能正常运行。
内容的提问来源于stack exchange,提问作者kartik
相关产品推荐
相关产品推荐

