Can't compile Android app due to com.android.dex.DexException (related to FacebookConnect plugin)

Hi there

I’m trying to compile my app for Android (command : ionic build android), and I get this error :

:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)

Here is my package.json (I have no issue with iOS compilation btw)

{
  "name": "xxxxxxx",
  "version": "1.0.0",
  "description": "xxxxxxxxxx",
  "dependencies": {
    "gulp": "^3.5.6",
    "gulp-sass": "^1.3.3",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0"
  },
  "devDependencies": {
    "bower": "^1.3.3",
    "gulp-util": "^2.2.14",
    "shelljs": "^0.3.0"
  },
  "cordovaPlugins": [
    "cordova-plugin-statusbar",
    "cordova-plugin-whitelist",
    "com.ionic.keyboard",
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-dialogs",
    "cordova-plugin-splashscreen",
    "cordova-plugin-camera",
    "cordova-plugin-file",
    "cordova-plugin-geolocation",
    "com.danielcwilson.plugins.googleanalytics",
    {
      "locator": "https://github.com/phonegap-build/PushPlugin.git",
      "id": "com.phonegap.plugins.PushPlugin"
    },
    {
      "locator": "https://github.com/Wizcorp/phonegap-facebook-plugin.git",
      "id": "com.phonegap.plugins.facebookconnect",
      "variables": {
        "APP_ID": "xxxxxxxxxx",
        "APP_NAME": "xxxxxx"
      }
    }
  ],
  "cordovaPlatforms": [
    "ios",
    "android"
  ]
}

If I remove the Facebook block and rebuild all :

rm -rf platforms plugins
ionic state restore
ionic build android

The build finishes without any error.

Anyone could help me? :smile:

Good news, you are not the only one who face this issue:


Basically, you have several plugins that require a different version of the same .jar file. (android-support-v4.jar)
I managed to make Facebook and google analytics working, using this fork https://github.com/diego-link-eggy/google-analytics-plugin
You will may have the same kind of issue with PushPlugin.

Thanks for your feedback, I’ll have a look :slight_smile:

I ended up using this plugin https://github.com/jeduan/cordova-plugin-facebook4 which is a fork of the well known Wizcorp/phonegap-facebook-plugin which doesn’t rely on a local version of android-support-v4, and so avoid this kind of issue.

1 Like

I had the same problem, so I replaced the Facebook plugin, and now My project is compiling without errors.

Thank you @thomasMary!

1 Like