Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: pros/cons adding dependencies

What are some pros/cons adding dependencies in build.gradle, instead of adding them as dependent libraries?

dependencies {
    compile project(':library')
    ...
    compile 'com.stackoverflow.android:some-great-library:1.0'
    ...
}

While working on Android projects, I've frequently come across with great libraries with the exact solution I've been looking for. However, as what I need is only a fraction of what those particular libraries have to offer, I'm worried if adding them as Gradle dependencies is an overkill.


Per @CommonsWare's comment, I have more specific questions.

Does adding dependencies:

  1. slow down compilation time at a noticeable rate?

  2. increase the size of release-apk and debug-apk, as much as the size of the added dependency?

like image 683
melvynkim Avatar asked May 31 '15 21:05

melvynkim


1 Answers

In Gradle dependencies are grouped into configurations as dependency configurations.External dependency is a dependency on some files built outside the current build, and stored in a repository of some kind, such as Maven central, or a corporate Maven or Ivy repository, or a directory in the local file system.

Dependency types:

External module dependency:

A dependency on an external module in some repository.

Project dependency:

A dependency on another project in the same build.

File dependency:

A dependency on a set of files on the local filesystem.

Client module dependency:

A dependency on an external module, where the artifacts are located in some repository but the module meta-data is specified by the local build. You use this kind of dependency when you want to override the meta-data for the module.

Gradle API dependency:

A dependency on the API of the current Gradle version. You use this kind of dependency when you are developing custom Gradle plugins and task types.

Local Groovy dependency:

A dependency on the Groovy version used by the current Gradle version. You use this kind of dependency when you are developing custom Gradle plugins and task types.

Pros adding dependencies:

  • In Gradle, you simply declare the “names” of your dependencies, and other layers determine where to get those dependencies from.

  • Code Change possible in SubProject.

  • Clear direct Dependency inclusive the Version of the used Library
    Clear indirect Dependencies managed (ie. the used Library use another Library - POM Files){from User Robert Halter).

  • online availablity dependent

  • The require sdk library is already synced with the project for the compilations.

Cons:

As such,it has got no cons but at the initial stage while adding dependencies we have to sync it which takes a bit time than simply dragging & dropping the jar file.

Slow down compilation time at a noticeable rate?

No,because the libraries are compiled only at the time of syncing.

Increase the size of release-apk and debug-apk, as much as the size of the added dependency?

No but practically yes because it only takes the size of the build file(binary size) which hardly increaces the size in bytes or kb which is hardly traceable.

So finally adding them as Gradle dependencies is an overkill when we only need to use a fraction of a particular library?

Definately,there might be a situation like in your case to use only a subset of a library.So in that case enabling ProGuard optimizes perform analysis at the bytecode level, inside and across methods to help make your app smaller and run faster without an overkill.

like image 190
SID --- Choke_de_Code Avatar answered Oct 16 '22 21:10

SID --- Choke_de_Code