android - Gradle: pros/cons adding dependencies -


what pros/cons adding dependencies in build.gradle, instead of adding them dependent libraries?

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

while working on android projects, i've come across great libraries exact solution i've been looking for. however, need fraction of particular libraries have offer, i'm worried if adding them gradle dependencies overkill.


per @commonsware's comment, have more specific questions.

does adding dependencies:

  1. slow down compilation time @ noticeable rate?

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

in gradle dependencies grouped configurations dependency configurations.external dependency dependency on files built outside current build, , stored in repository of kind, such maven central, or corporate maven or ivy repository, or directory in local file system.

dependency types:

external module dependency:

a dependency on external module in repository.

project dependency:

a dependency on project in same build.

file dependency:

a dependency on set of files on local filesystem.

client module dependency:

a dependency on external module, artifacts located in repository module meta-data specified local build. use kind of dependency when want override meta-data module.

gradle api dependency:

a dependency on api of current gradle version. use kind of dependency when developing custom gradle plugins , task types.

local groovy dependency:

a dependency on groovy version used current gradle version. use kind of dependency when developing custom gradle plugins , task types.

pros adding dependencies:

  • in gradle, declare “names” of dependencies, , other layers determine dependencies from.

  • code change possible in subproject.

  • clear direct dependency inclusive version of used library
    clear indirect dependencies managed (ie. used library use library - pom files){from user robert halter).

  • online availablity dependent

  • the require sdk library synced project compilations.

cons:

as such,it has got no cons @ initial stage while adding dependencies have sync takes bit time dragging & dropping jar file.

slow down compilation time @ noticeable rate?

no,because libraries compiled @ time of syncing.

increase size of release-apk , debug-apk, as size of added dependency?

no practically yes because takes size of build file(binary size) hardly increaces size in bytes or kb hardly traceable.

so adding them gradle dependencies overkill when need use fraction of particular library?

definately,there might situation in case use subset of library.so in case enabling proguard optimizes perform analysis @ bytecode level, inside , across methods make app smaller , run faster without overkill.

share|improve answer

the concern android app size. many of methods or classes may raise 64k limit on dex file , require multi-dex or jumbo mode enabling. may creates compatibility issue if have out-dated customers.

sometime may want work around extracting out classes needed, not easy job sometime.

if have proguard enabled, classes not being used can systematically removed.

share|improve answer

copying code of third-party library project causes problems supporting project if need use library of newer version? if you'll add dependency you'll need change version number in build system config

share|improve answer

what pros/cons adding dependencies subproject in gradle build project?

dependencies {     compile project(':library') } 

pros

  • change of code in :library subproject possible

cons

  • manage version of :library subproject

what pros/cons adding dependencies versioned dependent library in gradle build project?

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

pros

  • clear direct dependency inclusive version of used library
  • clear indirect dependencies managed (ie. used library use library - pom files)
  • a other person/group manage functionality of library - can focus on own code.

cons

  • none

does adding dependencies :library subproject slow down compilation time @ noticeable rate?

  • yes, must compiled too, because in source code in subproject
  • gradle optimze builtime input / output definition of task. see up-to-date markers while building.

does adding dependencies versioned dependent library slow down compilation time @ noticeable rate?

  • no, beacause libraries (.jar) compiled.

does adding dependencies increase size of release-apk , debug-apk, as size of added dependency?

  • the apk size increase binary size (.jar = zipped .class files) of added dependency.
  • (if have proguard enabled, classes not being used can systematically removed - user phdfong)
share|improve answer
    
compile 'com.stackoverflow.android:some-great-library:1.0' cons here are, op said, part of library remains unused if need of feature, adding dependencies versioned dependent library won't gradle try refetch updates? – rachit mishra jun 15 '15 @ 14:14
    
if version ist not snapshot (i.e. 1.0-snapshot) no need re cache final version. otherwise use ./gradlew ... --refresh-dependencies ... see docs.gradle.org/current/userguide/gradle_command_line.html – robert halter jun 15 '15 @ 17:47

i think question isn't dependent on gradle more use of "dependencies-management tools".

surely there situations need subset of library. in these situations, having import entire dependency may not best solution.

how "overkill"? depends on size of project. it's evaluate how "overkill" dependency can be: example if need simple function , importing library of 3mb, yes, bit 'overkill!

in addition have consider "big" libraries divided modules , can import module need. in case of android, @phdfond said, can use proguard remove unused classes @ build time, or can exclude them manually gradle:

//...       sourcesets {          main {              java {                  exclude '**/idontwantthisclass.java'              }          } 

but imho situation not common , can have lot of advantages using gradle or "dependencies management tool" (note in gradle, maven, ecc ... dependencies management 1 of functionalities).

for example if using gradle @ glance know dependencies , can add/remove them or change number update version. have ever think project can depends libs b , c, , both b , c can depends on 2 different versions of lib d? gradle can situations one. can't continue here because off-topic, can find lot of informations tools.

finally think important "cons" of "dependencies-management tools" initial learn , setup time. if never used tool gradle surely first times take more time drag , drop jar, encourage use gradle in projects, unless "toy-project".

share|improve answer

whether add third-party library dependency

you declare dependency third-party library when program uses code in library @ compilation time or @ runtime. means third-party code must reachable when program run, packed program. so, application size increases , undesired, because many users not huge applications. ridiculous, when program small , third-party library huge.

whether add third-party library module

i've never done that, if understood right, same copying library inside project, modify it. if use releases, there no compilation-time difference remote dependency compilation. same in previous paragraph, in addition free modify code (if third-party library license allowes it).

whether add extract code need

this best solution use, if need few methods library , not difficult extract them (again, assuming license allows this). on other hand, if use solid third-party functionality , want extract , modify in project, can face maintenance problems in future (if you'll decide migrate new version).

does adding dependencies: slow down compilation time @ noticeable rate?

with right gradle tuning (working daemon in background, using parallel processing) won't see dramatic changes in typical project.

does adding dependencies: increase size of release-apk , debug-apk, as size of added dependency?

dependency jar sent dex bytecode conversion project code. not 1:1 conversion in terms of size, answer no. proguard has tricks jar size minimization , maven has plugin packing dependent jars in one, obfuscated.

share|improve answer

i'd fundamentally different things.

1. gradle subproject

dependencies {   compile project(':foobarlib') } 

in first case, depending on android subproject, part of gradle project working on. may call type of dependency module, intellij does.

if wish make change, may , takes change visible gradle compilation of root gradle project.

2. android library project

dependencies {   compile 'com.example:foobarlib:2.1.0' } 

in second case, depending on artefact (i.e. archive in jar or aar format), not project. black box gradle project. gradle knows contains compiled classes (and resources in case of aar) project needs.

if wish make change in library, first need locate corresponding project edit sources, compile project , publish new artefact either local o remote maven repository. finally, project see changes made in other project, have update version number declared in dependency gradle knows have bring newly published artefact.

which 1 better?

it depends, of course. think of whether or not library has sense on own or if it's module of app. saw, second approach adds overhead if working on module of app , makes no sense version , distribute changes without rest of app.

share|improve answer

gradle dependency overkill

well if using stable library or satisfied current library features. when library has dependencies backward porting or has set of features or classes don't need.

the solution take need library, (only when sure suffice requirements)

and it's not

if want automatic updates , fixes library, ease of integration. many of libraries made , maintained everyday, may apk size doesn't matters us, library updates, gradle imports there.

concerns on apk size

a gradle dependency may have lot of unrelated stuff, backward support app doesn't require, in end increase application size, result in slow compilation too.

so, if library has single class or fewer class can directly add application in package. example google io app, libraries in different package.

you can control goes debug or release apk, debug dependencies use debugcompile, test dependencies use testcompile

adding library module dependency

adding library module speed build process download time required fetching dependency, can achieve enable offline sync gradle in android studio.

also library modules way, if have developed private library , use throughout own projects, if not case have library published , maintained on maven central , easier integrate own set of projects through gradle.

share|improve answer
1. slow down compilation time @ noticeable rate? 

short answer: yes.

long answer: using gradle in our project , there considerable difference in complitaion time have experienced. true if have project has multiple-module dependencies. not mention fact if keep adding lot of dependencies use bunch of classes each 1 of them run famous:

too many references: 66539 error; max 65536. 

i have experienced bunch of times(gradle , maven) myself when using libraries resource-intensive(play-services example).

2. `increase size of release-apk , debug-apk, as size of added dependency?` 

definately does. not release-apk since can optimize proguard whatever extend want. in case of debug-apk, have seen size variations of upto 5-6 mb.

just 2 cents. hope helps.

share|improve answer

your answer

 
discard

posting answer, agree privacy policy , terms of service.

not answer you're looking for? browse other questions tagged or ask own question.

Comments