Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

JS Park
JS Park
15,959 Points

How exactly does Gradle include 3rd party code?

Does it get the files over an Internet connection or are all 3rd party APIs included when you download or update Android Studio? I don't understand how one line of code - compile 'com.squareup.okhttp3:okhttp:3.3.1' - allows us to readily use the okhttp API.

1 Answer

Seth Kroger
Seth Kroger
56,407 Points

There are standard repositories that the authors of 3rd party libraries publish to. The 2 current standard repositories are JCenter and Maven Central, with Android Studio defaulting to JCenter. If you open your project's build.gradle file you'll see the reference to it in:

allprojects {
    repositories {
        jcenter()
    }
}

When you sync you're gradle file it will search any configured repositories for the dependencies you add and download them over the Internet.

JS Park
JS Park
15,959 Points

So you would need to have an Internet connection in order for the gradle file to sync?