gradle error DexException after adding facebook li

2019-07-24 04:00发布

问题:

after I added the fb library in the gradle dependences:

dependencies {
    compile 'com.mixpanel.android:mixpanel-android:4.5.2'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.facebook.android:facebook-android-sdk:3.22.0'
}

I started getting an error on gradle build:

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

thanks

回答1:

com.facebook.android:facebook-android-sdk:3.22.0This usually occurs because of a library getting referred to twice in the dependencies.

You can run the following command to see all the dependent libraries:

gradle -q dependencies 

You may need to do something like this to prevent the support library from being included twice:

*** Updated to reflect comment

compile ('com.facebook.android:facebook-android-sdk:3.22.0'){
        exclude module: 'support-v4'
}

See this related question: Building OutsystemsNow for android on Android Studio getting dexException