5

This is my first time trying to use gradle with an android project. I would like to add retrofit to my project but it keeps telling me.

Failed to resolve: com.squareup.retrofit:retrofit:1.9.0

Failed to resolve: com.squareup.okhttp:2.2.0

However google play services works perfectly.

My gradle file is as follows:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 21
  buildToolsVersion "21.1.2"

  defaultConfig {
    applicationId "test.gradel"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
 }
 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
 }
}

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  compile 'com.android.support:appcompat-v7:21.0.3'
  compile 'com.google.android.gms:play-services:6.5.87'
  compile group: "com.squareup.retrofit", name: "retrofit", version: "1.9.0"
  compile group: "com.squareup.okhttp", name: "okhttp", version: "2.2.0"
}

buildscript {
  repositories {
    jcenter()
  }

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

Any help would be greatly appreciated.

Thanks

Community
  • 1
  • 1
CodePorter
  • 230
  • 1
  • 3
  • 13

3 Answers3

2

The problem was fixed by creating a higher level build.gradle file and moved the following code into it.

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:1.1.2'
  }
}

allprojects {
  repositories {
    jcenter()
  }
}
CodePorter
  • 230
  • 1
  • 3
  • 13
1

You have to specify where you can find these artifacts. You have to add a repository block in your script.

You have to add this to your build.gradle

 repositories {
    mavenCentral()
 }

or

 repositories {
    jcenter()
 }

The Google play services library works because it is located in the Google Repository, which is downloaded with SDK Manager.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • I don't see it in this script. The repositories are specified only in the buildscript block, but you have to specify them also outside this block. – Gabriele Mariotti Mar 01 '15 at 23:23
0

In my case I was using gradle build in offline mode. toggling offline mode solved my issue.

Quraishi sazid
  • 91
  • 1
  • 12