Cordova - Multiple dex files define (annotation)

2019-01-20 11:09发布

问题:

I'm working on a project with ionic. After I installed the Facebook Plugin I'm not able to build the project for android anymore!

The command

ionic build android

gives me this error message

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

I'm reading a lot of tutorials/answers about this error and it seems to be related to the use of the Facebook Plugin with the Push Notification Plugin.

It's two days I'm trying a lot of different solutions, but none of those is working :(

Here are some information about my configuration:

plugin com.phonegap.plugins.PushPlugin version 2.5.0
plugin com.phonegap.plugins.facebookconnect version 0.11.0 (installed with the local repository, as indicated on github)
cordova version 5.0
ionic version 1.6.3

It looks like this problem is related to the "support-annotations" library loaded several times. Buy I really don't know how this is possible and where I can check it.

Can you help me? Do you have any idea of how to make this working? Is there a ionic/cordova configuration file where I can check the dependencies?

Thanks a lot in advance.

回答1:

Multiple dex files error is raised because of using multiple support jar files in the ionic / cordova project

you need to change build.gradle under platforms/android

find the below line

apply plugin:'com.android.application'

after add these below lines

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


回答2:

i solved same problem in my app the problem is

 com.android.support:support-v4:+

com.android.support:support-v4:+ file exist in /platforms/android/phonegap-facebook-plugin/Myapp-FacebookLib/libs

if you want only used facebook and Push Notification Plugin then simply commit the line in project.properties

#cordova.system.library.1=com.android.support:support-v4:+

Best way to solved this problem

1 First delete the android-support-v4.jar from /platforms/android/phonegap-facebook-plugin/Myapp-FacebookLib/libs

2 second step create a file name build-extras.gradle in /platforms/android/phonegap-facebook-plugin/Myapp-FacebookLib/

and type in file

dependencies {
compile "com.android.support:support-v4:+" }


回答3:

Push- and Facebook Plugins are conflicting by using different versions of android support libraries.

See my answer to this question: Android Studio cordova Push plugin



回答4:

We had the same problem with Google Analytics plugin with One Signal plugin and finally it was resolved by installing the plugins in different order;

  1. first install Google Analytics
  2. and then One Signal plugin, if you install in reverse order you will get that error.

This was our config:

  • Cordova CLI: 7.0.1
  • Ionic Framework Version: 3.3.0
  • Ionic CLI Version: 2.2.1
  • Ionic App Lib Version: 2.2.0

Cheers!



回答5:

Adding this to project.properties will resolve all of the V4 error instances.

cordova.system.library.7=com.android.support:appcompat-v7:27.1.0