74

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
AlexTa
  • 5,133
  • 3
  • 29
  • 46
Biboozz
  • 1,096
  • 2
  • 9
  • 18

17 Answers17

164

Most likely you are using the newly released cordova-android@6.3.0, 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 cordova-plugin-compat@1.2 which includes an engine constraint to prevent the Java files being re-installed into the cordova-android@6.3+ platform:

cordova plugin add cordova-plugin-compat@1.2

Another update (copypasted from comments)

After removing and adding cordova-plugin-compat@1.2, instead of removing and adding entire Android platform you can only remove files BuildHelper.java and PermissionHelper.java from folder platforms/android

Faust
  • 113
  • 5
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Hey tanks it work fine now. But i had to remove cordova-plugin-camera and i don't know if it is replaced my the new release – Biboozz Oct 04 '17 at 10:34
  • 3
    if you'd rather stick with `cordova-android@6.2.3`, make sure the `package.json` and `config.xml` in your project folder use `"6.2.3"` not `"^6.2.3"`, then delete the `platforms/android` folder, re-run `cordova prepare android`, and `cordova build android` should have no errors. – Michelle Norris Oct 05 '17 at 15:10
  • Should be worry about the warning: `The plugin 'cordova-plugin-compat' is required by (cordova-plugin-geolocation) but forcing removal`? – Made in Moon Oct 16 '17 at 20:01
  • 1
    I was also wondering about the warning that compat is required by some other plugins when I forced compat to be uninstalled. How ever you can do this without a problem since this is only a problem of Version 1.1.0 as far as I can tell. Once you force uninstalled it and just install the plugin again you get version 1.2 which does not cause the problem anymore. – Oliver Nov 07 '17 at 21:57
  • 6
    After removing and adding cordova-plugin-compat@1.2, instead of removing and adding entire Android platform you can only remove files BuildHelper.java and PermissionHelper.java from folder platforms/android/src/org/apache/cordova – Patrik Dec 18 '17 at 15:42
  • The solution to put cordova-plugin-compat@1.2 (instead of 1.1) worked for me even with android 7.1.2 – Josem Nov 09 '18 at 13:45
  • `cordova plugin rm cordova-plugin-compat --force` worked in my case, no need to add the plugin back in – Gerard Simpson May 29 '19 at 06:11
42

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 android@6.3.0
Eric
  • 9,870
  • 14
  • 66
  • 102
19

I had to do:

cordova plugin rm cordova-plugin-compat --force
cordova plugin add cordova-plugin-compat@1.2
cordova platform rm android
cordova platform add android@6.3.0

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

jlchereau
  • 1,152
  • 1
  • 7
  • 5
  • 1.2 version of it is for backward compatibility - "This plugin is no longer being worked on as the functionality provided by this plugin is now included in cordova-android 6.3.0. You should upgrade your application to use version 1.2.0 of this plugin. It will detect whether or not the plugin is required based on the version of cordova-android your app uses." – Adam Maloney Nov 09 '17 at 13:42
  • Thanks for this explanation @AdamMaloney! – Kunal Jan 29 '18 at 20:29
12

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 cordova-android@6.3.0. 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.

Alexander S.
  • 844
  • 1
  • 13
  • 29
  • 2
    THIS is what the BEST answer should be marked as! Cheers Alexander! I didn't feel good just having to downgrade to 6.3.0 as so many suggested - there had to be a better way. – Jester Mar 06 '18 at 14:20
  • Thank you , you saved my day – Paola Reyes Oct 25 '18 at 21:33
9

One solution: downgrade cordova android platform @6.2.3

$ cordova platform remove android && cordova platform add android@6.2.3

Made in Moon
  • 2,294
  • 17
  • 21
4

I'am using for Ionic 3 Project, I have to do:

ionic cordova plugin rm cordova-plugin-compat --force
ionic cordova plugin add cordova-plugin-compat@1.2
ionic cordova platform rm android
ionic cordova platform add android@6.3.0

it's work for me.

Sampath
  • 63,341
  • 64
  • 307
  • 441
MD.Riyaz
  • 412
  • 3
  • 9
4

With my Ionic 3 project it was enough to run:

ionic cordova plugin rm cordova-plugin-compat --force
ionic cordova plugin add cordova-plugin-compat@1.2

And then run a build again. No need to remove and add the platform.

Dark Smile
  • 65
  • 4
3

i had the same error, and i didn't have compat plugin in my plugins, i just run that code, then i built, it worked fine

$ cordova platform remove android && cordova platform add android@6.2.3
Maryam
  • 69
  • 1
  • 1
  • 7
2

Remove plugin cordova-plugin-compat forcefully android sdk above version 6.3.0 or equal because it is integrated with cordova android.

cordova plugin rm cordova-plugin-compat --force

As a reference below

https://cordova.apache.org/announcements/2017/09/27/android-release.html

Vinod Gehlot
  • 107
  • 7
1

cordova plugin rm cordova-plugin-compat --force

cordova platform rm android

cordova platform add android@6.3.0

cordova plugin add cordova-plugin-compat@1.2

in this order, works for me !! thanks a lot

1

This is the solution:

cordova plugin rm cordova-plugin-compat --force
clemens
  • 16,716
  • 11
  • 50
  • 65
0

I confirm that Answer by DaveAlden Works !!

But in the plugin.xml inside the cordova-plugin-compat I had a syntax error with less than sign '<', because it's illegal in xml.

This issue appears in visual studio, and you can't install plugin with the config manager because it detects this syntax error in xml on the plugin resource.

You must install with command line like DaveAlden says.

Ignore errors, And after install replace :

<engine name="cordova-android" version="<6.3.0"/>

by

<engine name="cordova-android" version="&lt;6.3.0"/>

And compilation run at the end!! :)

0

I have remove the Compat plugin after the update the dependency of other plugins; like Camera to the new version and it's work. Example: cordova plugin rm cordova-plugin-camera --save cordova plugin add cordova-plugin-camera@latest --save Post the new plugin addition the old version 2.3.0 was replaced with 4.0.2 for Camera plugin.

after this step. I have simply remove the plugin "Compat" cordova plugin rm cordova-plugin-compat --force

0

On Resume. This mean that plugin-camera is not compatible with the last version of android oreo

0

I am using Ionic 4 and this solved it for me (only takes a few seconds to run):

cordova clean
Baub
  • 723
  • 4
  • 21
  • 36
0

There may be mismatch of the plugins in the android builds. So better run 2 commands for successful build

cordova platform rm android
cordova platform add android

After wasted 2 days this seems to be only working solutions for me.

Pradeep Kachhawaha
  • 6,589
  • 2
  • 14
  • 13
0

None of the above solutions worked for me. For me the solution was upgrading gradle. I was using gradle 5.6.2. Updating to 5.6.4 then removing and adding my android platform and plugins did the trick.

brew upgrade gradle

Install / upgrade gradle on Mac OS X

rm -rf plugins/*

cordova platform rm android

cordova platform add android
tanner burton
  • 1,049
  • 13
  • 14