android - 多个 dex 文件定义 Lorg/apache/cordova/BuildHel

从昨天开始我就有麻烦了。在我的实习中,我遇到了以下构建错误,但我不明白为什么:

$ cordova build android

[...]

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;

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

BUILD FAILED

Total time: 3.379 secs
Error: /home/thor/Projects/App_CDP/platforms/android/gradlew: 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.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;

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

这里是cordova plugins list的输出,你可以看到我没有support-v4/v13冲突:

$ cordova plugin list
com.googlemaps.ios 2.2.0-fixed "Google Maps SDK for iOS"
com.moust.cordova.videoplayer 1.0.1 "Video Player"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-facebook4 1.9.1 "Facebook Connect"
cordova-plugin-file 4.0.0 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-googlemaps 1.4.0 "phonegap-googlemaps-plugin"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"
{}

这里还有更多信息:

$ cordova -v
7.0.1

$ ionic -v
2.1.4

最佳答案

您很可能正在使用新发布的 cordova-android@6.3.0,它现在包括 BuildHelper.java (如您的错误消息中所述)和PermissionHelper.java ,但您仍然拥有已弃用的 cordova-plugin-compat在您的项目中导致构建失败,因为它 also contains these classes .

要解决此问题,请从您的项目中删除 cordova-plugin-compat 以从 cordova-android 平台项目中卸载这些 Java 文件::

cordova plugin rm cordova-plugin-compat --force

更新

要保留此更改,请添加 cordova-plugin-compat@1.2,其中包含 engine constraint防止 Java 文件被重新安装到 cordova-android@6.3+ 平台:

cordova plugin add cordova-plugin-compat@1.2

另一个更新(从评论中复制粘贴)

删除和添加cordova-plugin-compat@1.2后,您只能从文件夹platforms/android中删除文件BuildHelper.java和PermissionHelper.java,而不是删除和添加整个Android平台

关于android - 多个 dex 文件定义 Lorg/apache/cordova/BuildHelper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46562289/

相关文章:

visual-studio-2010 - Visual Studio 2010 说在我更改源文件后构

Xcode 构建警告 - 目标完整性 - 配置文件仅针对 ProjectnameTests 目标到期

android - 如何使用 Ant 构建 Android 示例项目? build.xml 不存在

visual-studio-2010 - 除非我手动选择 "Rebuild",否则 Visual S

iphone - 如何在 Xcode 中减少构建时间/加快编译时间?

visual-studio - 为什么在 Visual Studio 中执行之前 F5 不重建项目?

c# - Await 运算符只能在 Async 方法中使用

c# - 使用 Visual Studio 2010 从命令行构建 C# 解决方案

java - 何时使用 gradle.properties 与 settings.gradle?

c++ - #将所有 .cpp 文件包含在一个编译单元中?