5

i'm facing the gradle error failed to resolve while including gson libraries.

I already checked for similar problem here, here and here but none of the solution proposed was suitable to me, i continue receiving the same error.

My build.gradle module:

android {
    compileSdkVersion 24
    buildToolsVersion '25.0.0'
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.code.gson:gson:2.8.0'
}

build.gradle project

buildscript {
repositories {
    mavenCentral()
    jcenter()
}
allprojects {
repositories {
    mavenCentral()
    jcenter()
}

As suggested in the answers it should be enough jcenter repository, as it is a superset of mavenCentral, i tried also different versions of gson, adding "+" et cetera but nothing is working.

Thanks in advance guys :)

Community
  • 1
  • 1
Fabio
  • 782
  • 4
  • 8
  • 25

4 Answers4

6

try using this in your app level build.gradle file

compile 'com.google.code.gson:gson:2.7'
Krishna Meena
  • 5,693
  • 5
  • 32
  • 44
  • Actually in my Android Studio 2.3 at home it works (OSX Environment), tomorrow i'll try again at work (Windows environment). Thanks, i'll let you know. How did you evaluate 2.7 as the version for my sdk version? – Fabio Mar 09 '17 at 18:42
  • in Android Studio 2.3 it automatically shows warning to update it to 2.7 – Krishna Meena Mar 09 '17 at 19:49
  • For some reason, in my case, adding the third digit of the version made Gradle fail. If I omitted it like in this answer, for example, like `'com.google.code.gson:gson:2.6'`, things worked out... – cavpollo Sep 14 '18 at 15:49
  • The current version is 2.8.5 – Emjey Jan 16 '20 at 06:44
5

Dear Fabio Add like this

compile 'com.android.support:multidex:1.0.1'
compile 'com.google.code.gson:gson:2.8.0'

see in attached snap enter image description here

Thanks

Dharmeshsharma
  • 683
  • 1
  • 11
  • 28
4

Try put this line in the build.gradle (Module:app) inside dependecies:

compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'

Here is an example:

Example project with the gson library added

Erick
  • 270
  • 3
  • 5
1

Try using the previous version of library , if still not working then download the .jar library file from Here and add it to your project. Also check out the possible solutions over here

Community
  • 1
  • 1
Manohar
  • 22,116
  • 9
  • 108
  • 144