-1

Developing app with Android studio using gradle. I have added this dependencies to it:

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'

but it says :

Error:A problem occurred configuring project ':app'.
> Could not download gson.jar (com.google.code.gson:gson:2.3.1)
   > Could not get resource 'https://jcenter.bintray.com/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar'.
      > Could not GET 'https://jcenter.bintray.com/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar'.
         > Connection to https://jcenter.bintray.com refused

Full source for my build.gradle files

Project:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

App:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "domain.myapplication"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.google.code.gson:gson:2.3.1'

}
AEMLoviji
  • 3,217
  • 9
  • 37
  • 61

2 Answers2

3

Define this in you gradle build script.

buildscript {
  repositories {
    mavenCentral()
    jcenter()
  }
  dependencies {
    ...
  }
}

allprojects {
  repositories {
    mavenCentral()
  }
}
Thomas R.
  • 7,988
  • 3
  • 30
  • 39
  • Error:(26, 13) Failed to resolve: com.google.code.gson:gson:2.3 Error:(25, 13) Failed to resolve: com.squareup.retrofit:retrofit:1.9.0 – AEMLoviji Sep 30 '15 at 13:25
  • compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' – Thomas R. Sep 30 '15 at 13:26
  • Even after "Sync Project with gradle files"? – Thomas R. Sep 30 '15 at 13:36
  • Try without jcenter. Comment this out and try again. Do you have a firewall or something like this? – Thomas R. Sep 30 '15 at 13:45
  • if i remove jcenter then it gives another error: Error:(25, 13) Failed to resolve: com.squareup.retrofit:retrofit:1.9.0 – AEMLoviji Sep 30 '15 at 13:47
  • Ok, try to invalidate caches and restart IDE. – Thomas R. Sep 30 '15 at 13:48
  • no success. But very interesting situation, i removed compile 'com.google.code.gson:gson:2.3.1' from dependencies and then rtied to sync it. i do not why it is still looks for gson. Very interesting. I have invalidated caches – AEMLoviji Sep 30 '15 at 13:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91003/discussion-between-aemloviji-and-thomas-r). – AEMLoviji Sep 30 '15 at 13:55
  • Specifically for me, need both buildscript and allprojects repositories – Nick Jan 07 '16 at 06:39
1

Call mavenCentral() in your build.gradle .

repositories {
    mavenCentral()
}
dependencies {

 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile 'com.google.code.gson:gson:2.3' 

}

add maven repository to build.gradle

Failed to resolve: com.google.code.gson:gson:2.3.1

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    same error: Error:A problem occurred configuring project ':app'. > Could not download gson.jar (com.google.code.gson:gson:2.3.1) > Could not get resource 'https://jcenter.bintray.com/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar'. > Could not GET 'https://jcenter.bintray.com/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar'. > Connection to https://jcenter.bintray.com refused – AEMLoviji Sep 30 '15 at 13:26
  • @AEMLoviji Please have a look here http://stackoverflow.com/questions/31795957/use-http-as-default-in-intellij-or-android-studio – IntelliJ Amiya Sep 30 '15 at 13:29
  • 1
    i have looked it. not my build.gradle file looks like below. but not works. same erorr. Connection to https://jcenter.bintray.com refused. repositories { mavenCentral() maven { url "http://repo1.maven.org/maven2" } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.google.code.gson:gson:2.3' } – AEMLoviji Sep 30 '15 at 13:35
  • 1
    Very interesting situation for me, if i removed compile 'com.google.code.gson:gson:2.3.1' from dependencies and then tried to sync it. I do not understand why it is still looks for gson. – AEMLoviji Oct 01 '15 at 04:16