Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple dex files define Lorg/apache/cordova/BuildHelper

I'm in trouble since yesterday. In my internship I faced the following build error, but I couldn't understand why :

$ 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.

Here is the output of cordova plugins list, I don't have the support-v4/v13 conflict as you can see :

$ 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"
{}

Here are also some more informations:

$ cordova -v
7.0.1

$ ionic -v
2.1.4
like image 929
Biboozz Avatar asked Oct 04 '17 10:10

Biboozz


4 Answers

Most likely you are using the newly released [email protected], which now includes BuildHelper.java (as noted in your error message) and PermissionHelper.java, but you still have the deprecated cordova-plugin-compat in your project which is causing the build to fail because it also contains these classes.

To fix this, remove cordova-plugin-compat from your project to uninstall these Java files from the cordova-android platform project::

cordova plugin rm cordova-plugin-compat --force

Update

To persist this change add [email protected] which includes an engine constraint to prevent the Java files being re-installed into the [email protected]+ platform:

cordova plugin add [email protected]

Another update (copypasted from comments)

After removing and adding [email protected], instead of removing and adding entire Android platform you can only remove files BuildHelper.java and PermissionHelper.java from folder platforms/android

like image 77
DaveAlden Avatar answered Nov 14 '22 20:11

DaveAlden


Going to add my 2 cents since none of the solutions work for me. Only thing that worked for me:

cordova plugin rm cordova-plugin-compat --force
cordova platform rm android
cordova platform add [email protected]
like image 21
Eric Avatar answered Nov 14 '22 19:11

Eric


I had to do:

cordova plugin rm cordova-plugin-compat --force
cordova plugin add [email protected]
cordova platform rm android
cordova platform add [email protected]

considering you can't simply remove cordova-plugin-compat because plugins like cordova-plugin-file depend on it.

like image 19
jlchereau Avatar answered Nov 14 '22 21:11

jlchereau


I know the the question already answered, but I want to add link to the official release notes:

https://cordova.apache.org/news/2017/11/10/plugins-release.html

In our last plugins release, we deprecated cordova-plugin-compat since it got integrated into [email protected]. So for this release cycle, we have removed the dependency from plugins that were relying on it and gave the plugins a major version jump. The follow plugins have dropped cordova-plugin-compat: cordova-plugin-camera, cordova-plugin-contacts, cordova-plugin-file, cordova-plugin-geolocation, cordova-plugin-media, and cordova-plugin-media-capture.

So, make sure you update all listed plugins to the version posted in release notes.

like image 12
Alexander S. Avatar answered Nov 14 '22 21:11

Alexander S.