Conflict when using Gson + Facebook API

1

Talk about it, all right?

Has anyone used the Gson library in the same project where the SDK was used?

The problem happened when I used the Facebook SDK to allow in-app login through the Facebook account. This routine also worked perfectly, but it does Gson bugar.

In practice, I'm using the following dependencies in my Gradle:

compile 'com.facebook.android:facebook-android-sdk:4.8.1'
compile 'com.google.code.gson:gson:2.7'

In the code, the error happens when I try to instantiate Gson, in this line:

 Gson g = new Gson();

And the error that happens is this:

 Caused by: java.lang.VerifyError: com/google/gson/Gson

I've done a lot of research and found people with similar errors, so I understand the SDK SDK also uses Gson, so this conflict happens. Some solutions I found for this type of problem are as follows, but none of them solved my problem:

Add mavenCentral () in the repositories: I already did but did not solve it.

repositories {
    mavenCentral()
}

Give an "exclude" in Gson's Facebook SDK: also tried and did not work.

    
asked by anonymous 25.08.2016 / 22:33

2 answers

1

Look ... In an attempt to reduce the number of methods to a number less than 64K, I started measuring the number of methods of my dependencies using this site Methods Count and then I realized that this dependency

com.google.android.gms:play-services:8.4.0

I had a very large number of methods. Then it replaces it with the following: 'com.google.android.gms:play-services-ads:8.4.0'

Doing this, the conflict is gone and the problem seems to be fixed.

    
26.08.2016 / 19:53
0

Go to your build.grade file under the / app directory and add the multiDexEnabled false line inside defaultConfig , example:

defaultConfig {
    applicationId "com.exemple.exemple"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
    multiDexEnabled false
}
    
25.08.2016 / 22:48