如何解决 Program type already present: com.google.zxing.BarcodeFormat in ionic 4
How to solve Program type already present: com.google.zxing.BarcodeFormat in ionic 4
我正在使用ionic 4。当我的项目有facebook插件和BarcodeScanner插件并输入ionic cordova 运行 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
这可能是一个依赖性问题。
如果 class 在运行时 class 路径中出现不止一次,您会收到类似于以下内容的错误:
Program type already present com.example.MyClass
此错误通常是由于以下情况之一造成的:
二进制依赖项包括一个库,您的应用程序还作为直接依赖项包含该库。
例如,您的应用声明了对库 A 和库 B 的直接依赖,但库 A 的二进制文件中已包含库 B。要解决此问题,请删除库 B 作为直接依赖项。
您的应用对同一库具有本地二进制依赖项和远程二进制依赖项。
要解决此问题,请删除其中一个二进制依赖项,删除多余的。 (查看是否添加了相同的库作为依赖项)
关注此 link 了解更多详情 - Here
从回购来看,它似乎不是很活跃,其他人 opened an issue for this back in July 没有确认。
我想此时您需要问问自己,您是否愿意为不受支持的插件解决构建错误,或者您是否只想让该功能正常工作,因为还有其他库可以为你.
例如:
您需要仔细检查它是否扫描了您要查找的确切条形码,但它们不仅支持基本的二维码,而且希望不会与其他插件发生冲突。
更新 - 我今天才再看一遍,如果你真的想解决它,那么你可以使用 .
来解决构建问题
经过数周的搜索,以下步骤帮助我解决了这个问题:
1.Remove android 平台。
2.Install cordova-plugin-facebook4
3.Create build.gradle 在 /plugins/cordova-plugin-facebook4/
4.Copy
dependencies { compile("com.facebook.android:facebook-android-sdk:4.37.0") { exclude group: 'com.google.zxing' } }
到../plugins/cordova-plugin-facebook4/build.gradle
5.Edit ../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.Add android 平台和构建
嗯,我找到了一个适合我的解决方案,使用 barcodescanner
和 facebook4
进入文件夹plugins/cordova-plugin-facebook4
创建文件“build.gradle”并添加这些行
dependencies {compile("com.facebook.android:facebook-android-sdk:4.37.0") {exclude group:'com.google.zxing'}}
打开文件 plugins/cordova-plugin-facebook4/plugin.xml 并替换行:
<framework src="com.facebook.android:facebook-android-sdk:$FACEBOOK_ANDROID_SDK_VERSION"/>
到
<framework src="build.gradle" custom="true" type="gradleReference"/>
在您的应用程序路径中使用这些命令删除和添加 android 平台
ionic cordova platform rm android
ionic cordova platform add android
终于构建您的应用程序
ionic cordova build android
我正在使用ionic 4。当我的项目有facebook插件和BarcodeScanner插件并输入ionic cordova 运行 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
这可能是一个依赖性问题。
如果 class 在运行时 class 路径中出现不止一次,您会收到类似于以下内容的错误:
Program type already present com.example.MyClass
此错误通常是由于以下情况之一造成的:
二进制依赖项包括一个库,您的应用程序还作为直接依赖项包含该库。
例如,您的应用声明了对库 A 和库 B 的直接依赖,但库 A 的二进制文件中已包含库 B。要解决此问题,请删除库 B 作为直接依赖项。
您的应用对同一库具有本地二进制依赖项和远程二进制依赖项。
要解决此问题,请删除其中一个二进制依赖项,删除多余的。 (查看是否添加了相同的库作为依赖项)
关注此 link 了解更多详情 - Here
从回购来看,它似乎不是很活跃,其他人 opened an issue for this back in July 没有确认。
我想此时您需要问问自己,您是否愿意为不受支持的插件解决构建错误,或者您是否只想让该功能正常工作,因为还有其他库可以为你.
例如:
您需要仔细检查它是否扫描了您要查找的确切条形码,但它们不仅支持基本的二维码,而且希望不会与其他插件发生冲突。
更新 - 我今天才再看一遍,如果你真的想解决它,那么你可以使用
经过数周的搜索,以下步骤帮助我解决了这个问题:
1.Remove android 平台。
2.Install cordova-plugin-facebook4
3.Create build.gradle 在 /plugins/cordova-plugin-facebook4/
4.Copy
dependencies { compile("com.facebook.android:facebook-android-sdk:4.37.0") { exclude group: 'com.google.zxing' } }
到../plugins/cordova-plugin-facebook4/build.gradle
5.Edit ../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.Add android 平台和构建
嗯,我找到了一个适合我的解决方案,使用 barcodescanner
和 facebook4
进入文件夹plugins/cordova-plugin-facebook4
创建文件“build.gradle”并添加这些行
dependencies {compile("com.facebook.android:facebook-android-sdk:4.37.0") {exclude group:'com.google.zxing'}}
打开文件 plugins/cordova-plugin-facebook4/plugin.xml 并替换行:
<framework src="com.facebook.android:facebook-android-sdk:$FACEBOOK_ANDROID_SDK_VERSION"/>
到
<framework src="build.gradle" custom="true" type="gradleReference"/>
在您的应用程序路径中使用这些命令删除和添加 android 平台
ionic cordova platform rm android ionic cordova platform add android
终于构建您的应用程序
ionic cordova build android