Erro: Unable to merge dex when add cordova-plugin-facebook4

Good Morning,

I’m new to the forum and I’m starting with Ionic.
I have a project “linked” to Ionic PRO and everything works perfectly.
Now I have added the “cordova-plugin-facebook4” to implement social login:

$ ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID=“123456789” --variable APP_NAME=“myApplication”
$ npm install --save @ionic-native/facebook

But now when I compile with:

$ ionic cordova build android

I get this error:

:transformDexArchiveWithExternalLibsDexMergerForDebug

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformDexArchiveWithExternalLibsDexMergerForDebug’.

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

FAILED
36 actionable tasks: 2 executed, 34 up-to-date

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

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s
(node:997488) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformDexArchiveWithExternalLibsDexMergerForDebug’.

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

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

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s
(node:997488) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Any idea of what is happening?
Thank you so much

There is a long running thread about the Facebook plugin, e.g. https://github.com/jeduan/cordova-plugin-facebook4/issues/507. The gist of it is library incompatibilities and many people including myself have used the 1.7.4 version of the plugin to get it to work. I.e. you need to remove the version of the plugin you have and do this instead:

cordova plugin add cordova-plugin-facebook4@1.7.4 --save --variable APP_ID="<myid>" --variable APP_NAME="<myname>"