elcuco
elcuco

Reputation: 9208

AAR dependencies - bundle or not?

I am developing my own SDK, which in turn depends on some 3rd party SDKS. For example - OkHttp.

Should I add OkHttp to my build.gradle, or let the users of my SDK include that? In this scenario, they will probably "anyway" use it, so its safe to say they already have it.

Another point to add - not all paths of my SDK needs "OkHttp", so, in theory, some user of my SDK could use those parts only, and have not OkHttp on his APK.

Another thing I am contemplating: If I do embed OkHttp on by build.gradle - how can users of my SDK use that OkHttp library, instead of consuming another replica?

Upvotes: 2

Views: 1989

Answers (4)

Saran Sankaran
Saran Sankaran

Reputation: 2606

I will answer your questions in a reverse order

Another thing I am contemplating: If I do embed OkHttp on by build.gradle - how can users of my SDK use that OkHttp library, instead of consuming another replica?

How Gradle build system works is suppose, In my project I use your library and I'm using v2 of OkHttp and your library is using V1 of OkHttp, then the gradle will automatically use the latest version. You can read about it here

Another point to add - not all paths of my SDK needs "OkHttp", so, in theory, some user of my SDK could use those parts only, and have not OkHttp on his APK.

In my project I use your library and it uses OkHttp, whereas I don't use it in my project also, I'm not using the part of your library where you are using OkHttp but still my APK will include OKHttp in it. This can be avoided either by splitting your library into two separate libraries or me using proguard in my Project.

Should I add OkHttp to my build.gradle, or let the users of my SDK include that? In this scenario, they will probably "anyway" use it, so its safe to say they already have it.

You should not bundle it in your library you just use implementation and let the user of your library decide if he wants to exclude it or not.

Upvotes: 0

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363825

Should I add OkHttp to my build.gradle, or let the users of my SDK include that?

Adding the dependencies in build.gradle doesn't mean packaging the dependencies inside the aar file. The aar file doesn't contain the transitive dependencies and doesn't have a pom file which describes the dependencies used by the library.

Uploading the artifact in a maven repository you will have your aar and a pom file which will contains the dependencies list.
In this way gradle will automatically download all the dependencies tree and you can configure gradle to exclude same libraries.

Upvotes: 6

Alireza Tizfahmfard
Alireza Tizfahmfard

Reputation: 583

You need knows about api and implementation in the gradle The link will be helpful

Api: Role: Declaring ,API, dependencies

Consumable? no

Resolveable? no

Description: This is where you should declare dependencies which are transitively exported to consumers, for compile.

Implemetation: Role: Declaring, implementation, dependencies

Consumable? no

Resolveable? no

Description: This is where you should declare dependencies which are purely internal and not meant to be exposed to consumers.

Upvotes: -1

Martin Zeitler
Martin Zeitler

Reputation: 76669

Use implementation and package it - the consumer can still exclude it.

One cannot depend on something and then not package it; this won't build.

In the application package, it can/must only exists once ...so what's the point?

Upvotes: 2

Related Questions