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

I am building an application using cordova and Ionic framework.

However, now when I build my project, I encounter an error:

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

Other SO solutions point to conflicts of several android-support-v4.jar , however the only android-support-v4.jar that I can find is in the facebook plugin.

Another solution mentions conflicting versions (i.e. android-support-v4.jar conflicting with android-support-v13.jar ) - again, I don't see links to android-support-v13.jar in my project.

Another solution was conflicting android-support-annotations.jar and android-support-v4.jar : several dex files defining landroid / support / annotation / AnimRes . I can not find the android-support-annotations.jar files in my project, other than what was created in: myProject\platforms\android\build\intermediates\pre-dexed\debug enter image description here

However, I do not understand how this is 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 identifier and name of the facebook application)

+4
source share
2 answers

You need to exclude support for android-support-v4.jar, which is included in the Wizcorp Facebook plugin. The trick is simple, you need to create build-extras.gradle inside the / android platforms and add the following:

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

And what is it, now every plugin that uses lib support for Android will work with this FB plugin. You could probably put this somewhere in the default build.gradle, but I could not pinpoint where this build-extras file is automatically included, so its fine.

+15
source

Try cleaning the project using cordova clean .

In my case it works.

0
source

All Articles