Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Networking Getting the OkHttp Library Using Gradle

gradle sync failing

hey guys, please help

I have copied the following code "compile 'com.squareup.okhttp:okhttp:2.4.0' " form the okhttp site

but now its saying

Error:(24, 13) Failed to resolve: com.squareup.okhttp:okhttp:2.4.0

how do I resolve this

I am running using jdk 7 here is my gradle file code

apply plugin: 'com.android.application'

android { compileSdkVersion 22 buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "muzinda.com.mamiriroekunze"
    minSdkVersion 14
    targetSdkVersion 22
    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:22.0.0' compile 'com.squareup.okhttp:okhttp:2.4.0' }

Go to file->settings->gradle and check the box use auto import .

2 Answers

eric hughes
eric hughes
12,345 Points

I have been having this issue as well, I just switched from iOS to Android because I should keep practicing my Java because that's what we are learning at my school. ALSO go in your android sdk manager and download everything they recommend, from all the tools, plugins whatever, you can skip the WEAR and TV ones and it should work. Otherwise keep looking online, a lot of the answers that I have been seeing is reverting back to 21.1.2 but this does not seem that efficient, apparently the update to 5.0 lollipop is causing a lot of problems right now for new developers who don't have a lot of experience with Android Studio

this is my build.gradle (Module: app)

apply plugin: 'com.android.application'

android { compileSdkVersion 22 //change buildToolsVersion buildToolsVersion '21.1.2'

defaultConfig {
    applicationId "com.httpescapingminimumwage.myapplication"

// right here is my domain I would switch it to whatever you currently have //along with the name of your app minSdkVersion 16 targetSdkVersion 22 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:22.2.0' testCompile 'com.squareup.okhttp:mockwebserver:2.4.0' }

I have exactly the same problem, to prove it is not my code and for TeamTreeHouse to reproduce this issue, just create a brand new project, and simply add this line to build.gradle:

compile 'com.squareup.okhttp:okhttp:2.4.0'

Error:(24, 13) Failed to resolve: com.squareup.okhttp:okhttp:2.4.0 <a href="openFile">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>