3

In my Android Studio project, I get warnings like this - stating there's a newer version available. (gson: using 2.3.1 but 2.4 is available)

Android Studio warning

But when I then update my gradle file to use 2.4 instead:

compile 'com.google.code.gson:gson:2.4'

I get the error that this cannot be resolved: Android Studio error

(I also tried 2.4.0 without any improvement)

So - can anybody explain to me, why the new version is offered, but cannot be resolved? What am I missing?

Thanks!

Zordid
  • 10,451
  • 11
  • 42
  • 58
  • 1
    please post your project build.gradle – sanemars Feb 17 '16 at 09:22
  • 1
    According to [mvnrepository](http://mvnrepository.com/artifact/com.google.code.gson/gson) the latest version is `2.6.1`. Though `com.google.code.gson:gson:2.4` should work – Atif Farrukh Feb 17 '16 at 09:24
  • From what you've shown so far, 2.4 should work. Clearly us answerers are missing something, we may not be able to figure it out without additional information. Can you show your repositories section please. Note that there will be (at least) two of them. – RaGe Feb 19 '16 at 11:37

4 Answers4

1

Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object.

You can use below Stable version

compile 'com.google.code.gson:gson:2.3'

Latest is Gson 2.6.1

compile 'com.google.code.gson:gson:2.6.1'
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • I DO use 2.3.1 as you can see. Then the warning says "use 2.4, it's newer!" - and when I do, it says "Well, no, I don't have any version 2.4!" That is my question. Not whether 2.3 works or 2.6.1... :) – Zordid Feb 17 '16 at 12:33
  • as you can see, the 2.4 is also a stable release http://mvnrepository.com/artifact/com.google.code.gson/gson – Farhad Feb 17 '16 at 12:38
  • 2.6.1 does not work either. "Failed to resolve: com.google.code.gson:gson:2.6.1" – Zordid Feb 17 '16 at 12:41
1

I have the same problem. "Invalidate Caches / Restart" in Android Studio's File menu solve this.

0

As of Gradle 1.7, jcenter() is a superset of mavenCentral()

Jars will be downloaded from online central jcenter repository. so adding just the following statement is working.

dependencies {
compile 'com.google.code.gson:gson:2.2.+'
}
Farhad
  • 12,178
  • 5
  • 32
  • 60
  • 1
    There are a few situations in which using dynamic version for dependencies makes sense - such as when you're actively developing the library you're depending on. In most standard situations though, like this one, you should not use dynamic versions because it makes your build non deterministic. Your build could just start randomly failing if a new incompatible version of the library becomes available. – RaGe Feb 17 '16 at 12:02
  • Of course it is. But that has nothing to do with my question "Why is 2.4 offered, but not available?" – Zordid Feb 17 '16 at 12:32
  • You may take a look at http://stackoverflow.com/questions/28683327/how-to-check-if-gradle-dependency-has-new-version – Farhad Feb 17 '16 at 12:37
  • is your internet connection OK? –  Oct 25 '16 at 11:10
0

add repositories in your build.gradle, it will work

repositories {
    mavenCentral()
}
GS Nayma
  • 1,745
  • 19
  • 24
  • Of course I got the repository - jcenter - in my gradle file. mavenCentral is not the standard one. Plus, this does not answer my question "why is 2.4 offered - but when I try to use it, not there?" – Zordid Feb 17 '16 at 12:31
  • @Zordid 2.4 is available, I don't know why it is not working in ur side because I am using same version with mavenCentral its working fine for me. – GS Nayma Feb 17 '16 at 12:52