Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Multiple dex files define Landroid/support/annotations/AnimRes with Admob and Facebook Cordova plugins

I'm building an app using cordova and the Ionic framework.

  • I'm using the Wizcorp facebook plugin:
    https://github.com/Wizcorp/phonegap-facebook-plugin .
  • and I recently added the google admob plugin:
    https://github.com/floatinghotpot/cordova-admob-pro

However now when I build my project I'm met with the error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotations/AnimRes;

Other SO solutions mention multiple android-support-v4.jar files conflicting, however the only android-support-v4.jar file I can find is within the facebook plugin.

Another solution mentioned conflicting versions (i.e android-support-v4.jar conflicting with android-support-v13.jar) - again, I cannot see any references to android-support-v13.jar within my project.

Another solution was conflicting android-support-annotations.jar and android-support-v4.jar: multiple dex files define landroid/support/annotation/AnimRes . I cannot find any android-support-annotations.jar files within my project, except something that is created in: myProject\platforms\android\build\intermediates\pre-dexed\debug enter image description here

However I don't understand how this is getting created.

How can I solve this problem? The problem can be easily reproduced:

>ionic start myApp tabs
>cd myApp
>cordova plugin add https://github.com/Wizcorp/phonegap-facebook-plugin.git --variable APP_ID="123456789" --variable APP_NAME="myApplication"
>cordova plugin add cordova-plugin-admobpro
>ionic platform android
>ionic build android 

(where APP_ID and APP_NAME are the ID and name of a facebook application)

like image 442
Benzilla Avatar asked Dec 06 '22 20:12

Benzilla


1 Answers

You need to exclude android-support-v4.jar that got included by Wizcorp Facebook plugin. Trick is simple you need to create build-extras.gradle inside platforms/android and add following:

configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }

And that's it, now every plugin that uses android support lib will work with this FB plugin. You could probably put this somewhere in default build.gradle but i couldn't figure out exactly where, this build-extras file get auto included so its fine.

like image 61
Mladen Petrovic Avatar answered Mar 16 '23 22:03

Mladen Petrovic