解决cordova异常DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper
环境
cordova:7.0.1
cordova-android:6.3.0
cordova插件:
$ cordova plugin list
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-file 4.0.0 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-geolocation 2.4.3 "Geolocation"
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 build android报Multiple dex files define Lorg/apache/cordova/BuildHelper错误:
$ 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
解决方法
这是因为cordova-plugin-compat的BuildHelper.java和PermissionHelper.java已合并到cordova-android@6.3.0,如果项目包含了cordova-plugin-compat就会导致多个dex文件的错误提示。
删除cordova-plugin-compat可以解决这个问题。
cordova plugin rm cordova-plugin-compat --force