Journal for Developers

Gradle Declaring Dependencies – Android

Gradle Android Dependencies
0 47

Notice: Undefined index: rate in /home/content/p3pnexwpnas11_data03/84/3795084/html/wp-content/themes/publisher/includes/functions.php on line 5360
1 min read

In the Android App, once the repositories have been defined, we can then define the dependencies or artifacts that we are looking to use in the App from those repositories.

Dependencies that are resolved from repositories are referred to as external module dependencies.

Dependencies are configured in the dependencies script block. The syntax used is the name of the configuration we want to add the dependency to followed by dependency notation.

dependencies {
  compile ""

We can also use the Groovy map syntax to identify dependencies by their group, name, and version.

dependencies {
  compile group: "", name: "design", version: "25.3.1"

Sometimes we need to add files as dependencies. Files dependencies are declared in the very same manner as managed dependencies. However, instead of a dependency notation we simply use a file collection or a file tree. In the below example, we are adding two jar files as dependencies by creating a files collections.

dependencies {
  compile files("libs/foo.jar", "libs/bar.jar")

We can also use fileTree which allows us to do things like specify filters. This is useful if we want the number of files within the directory.

dependencies {
  compile fileTree(dir: "libs", include: "*.jar")

Gradle also supports projects dependencies which are dependencies on other Gradle projects within a single multi-project build which we will be sharing in details in the next part. So stay tuned!

Subscribe to our Journal

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!