Conflict when using Gson + Facebook API

Asked

Viewed 63 times

1

Talk guys, all right?

Someone there has used the Gson library in the same project where the Facebook SDK was used?

The problem happened when I used the Facebook SDK to allow logging into the application through the Facebook account. This routine also worked perfectly, but it makes the Gson bugar.

In practice, I am 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, on that line:

 Gson g = new Gson();

And the mistake that happens is this:

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

I’ve researched a lot and found people with similar errors, so I understand the Facebook 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() to repositories: I’ve done but not solved.

repositories {
    mavenCentral()
}

Give an "exclude" on Facebook SDK Gson: also tried and did not work.

2 answers

1


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

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

was with a very large number of methods. So replace it with the following: 'com.google.android.gms:play-services-ads:8.4.0'

So the conflict is gone and the problem seems to be solved.

0

It goes in your file build grade., inside the directory /app and add the line multiDexEnabled false within the defaultConfig, example:

defaultConfig {
    applicationId "com.exemple.exemple"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
    multiDexEnabled false
}
  • First, thank you for answering! But I can’t switch to false, because I have more than 64k methods in my file. Dex (according to the error that is presented to me). I will put the error in another comment to organize better:

  • Error:The number of method References in a . Dex file cannot exceed 64K. Learn how to resolve this Issue at https://developer.android.com/tools/building/multidex.html </code>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.