ionic4 - 如何解决 ionic 4 中程序类型已存在 : com. google.zxing.BarcodeFormat

标签 ionic4

我使用的是 ionic 4。当我的项目有 facebook 插件和 BarcodeScanner 插件并输入 ionic cordova run android 时,会出现以下错误:

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.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

我使用以下命令下载这两个插件:

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

ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="app_id" --variable APP_NAME="app_name"
npm install --save @ionic-native/facebook

最佳答案

经过几周的搜索,以下步骤帮助我解决了问题:

1.移除android平台。

2.安装cordova-plugin-facebook4

3.在/plugins/cordova-plugin-facebook4/中创建build.gradle

4.复制

dependencies { compile("com.facebook.android:facebook-android-sdk:4.37.0") { exclude group: 'com.google.zxing' } }

到../plugins/cordova-plugin-facebook4/build.gradle

5.编辑../plugins/cordova-plugin-facebook4/plugins.xml更改

<framework src="com.facebook.android:facebook-android-sdk:$FACEBOOK_ANDROID_SDK_VERSION"/>

<framework src="build.gradle" custom="true" type="gradleReference"/>

6.添加android平台并构建

关于ionic4 - 如何解决 ionic 4 中程序类型已存在 : com. google.zxing.BarcodeFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58051881/

相关文章:

javascript - Ionic 4,试图用 col-6 显示每行 2 个,但每行仍然放置太多

css - 样式自定义组件及其开槽元素

angular - 从 ionic 后退按钮导航后,Ionic 4 ionViewDidEnter() 未触发

javascript - 我们如何在 ionic 应用程序中隐藏启动画面?

angular - ionic 4 google-maps 5 beta "TypeError: Cannot read property ' BaseClass' of null"

ionic-framework - 在 ionic 4 上添加刷卡火种

javascript - 类型错误 : Cannot read property '0' of null at SelectedDateService. ngOnInit

angular - ionic 4 + Angular : routerLink only works first time

javascript - Chartjs : How do you toggle the visibility of charts in Ionic 4

css - 在 ionic 4+ 中设置 ion-toolbar shadow dom 的 .toolbar-container 样式