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:
slow down compilation time @ noticeable rate?
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.
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. | ||||
|
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 | |||
|
what pros/cons adding dependencies subproject in gradle build project? pros
cons
what pros/cons adding dependencies versioned dependent library in gradle build project? pros
cons
does adding dependencies :library subproject slow down compilation time @ noticeable rate?
does adding dependencies versioned dependent library slow down compilation time @ noticeable rate?
does adding dependencies increase size of release-apk , debug-apk, as size of added dependency?
| |||||||||
|
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: 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". | |||
|
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.
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).
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).
with right gradle tuning (working daemon in background, using parallel processing) won't see dramatic changes in typical project.
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. | ||||
|
i'd fundamentally different things. 1. gradle subproject in first case, depending on android subproject, part of gradle project working on. may call type of dependency if wish make change, may , takes change visible gradle compilation of root gradle project. 2. android library project in second case, depending on if wish make change in library, first need locate corresponding project edit sources, compile project , publish new artefact either local o remote 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. | |||
|
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)
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.
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
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. | ||||
|
short answer: yes. long answer: using i have experienced bunch of times( 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. | |||
|