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

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

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

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

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)

回答1:

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.



回答2:

You should try to clean your project by using cordova clean.

In my case it works.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!