Libraries and Dependencies

Roughly speaking, the code and assets that make up an app come from three sources:

  1. The source that you and people that you know are writing for this app.
  2. The source that comes from your compileSdkVersion, representing the Android SDK that you are linking to.
  3. Everything else, generally referred to as dependencies. These are libraries, written by Google, independent Android developers, major firms, and so on. Every modern Android app uses libraries, and bigger apps use more libraries.

From a pure technical standpoint, most dependencies are listed in build.gradle files in dependencies closures. We have seen two of these in this chapter.

One dependencies closure appears in the project-level build.gradle file, inside of a buildscript closure:

  dependencies {
    classpath "com.android.tools.build:gradle:7.0.2"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"

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

Those list places where Gradle plugins come from. You are always depending upon the Android Gradle Plugin, and some other developers publish Gradle plugins that you may elect to use in the future. Kotlin users will also use a Kotlin plugin.

However, the dependencies closure that we tend to think about the most is the one in our module’s build.gradle file, such as app/build.gradle, such as this one from the starter project:

dependencies {

  implementation 'androidx.core:core-ktx:1.6.0'
  implementation 'androidx.appcompat:appcompat:1.3.1'
  implementation 'com.google.android.material:material:1.4.0'
  implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
  testImplementation 'junit:junit:4.+'
  androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

Here, there are three types of statements:

(we will explore the differences between those in an upcoming chapter)

Our starter project has eight statements in app/build.gradle attempting to pull in dependencies:

Most likely, you will be adding other similar statements to this set, plus perhaps deleting ones that you are not actually using (e.g., the fileTree() one). We will see how to add other libraries as the book progresses, as many of the things that are common in Android app development require additional libraries.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.