5

I'm working on Android Library project and want to add Picasso to my library. I've noticed that different libraries use different approaches to do this:

  • Some libraries use static library dependency (like gif_encoder and gif_decoder libraries in Glide lib)
  • Some libraries use usual dynamic gradle or pom dependencies (like Picasso uses OKHttp or Wire uses Retrofit and RxJava). I don't mean dynamic versions here marked with + sign (like 2.3.3+)
  • Some libraries require adding the explicit dependence to some lib together with the target library (like RxAndroid uses RxJava)

So the question: what's the best way to add third party libraries to the Android library project? I mean the way that would help to simplify library integration process for the end-user and to avoid versions conflict and other potential issues. What are the advantages and disadvantages of a particular approach?

Olga Konoreva
  • 1,338
  • 13
  • 20
  • From my point of view, adding the dependencies in the library module gradle is the best approach. By doing that you make transparent to the end user of what you are using to fufill its purpose. If you make the user import your dependencies together, you add complexity to process of importing your library and even errors in case the user do not import them. However, if user is using a different version of the library that the module uses, you might get conflict between the two, so the user you have to solve them in the gradle file. – E. Fernandes May 11 '16 at 14:47

1 Answers1

2

Most of the time you don't really have a choice, you will have to follow the library installation recommendations.

If all options are available I think IMHO that it is much easier with Gradle or Maven since the only thing you have to do is generally adding one line into your configuration file to setup a new library.

When an update is available, you change the version and the system will automatically download and update the library for you.

When you have to use static libraries, you need to setup all by yourself and link the external library to your project. Now I keep only static libraries if I have to customize some code in it.

I am not an expert on the subject but since I migrated to Android Studio, Gradle saved me a lot of time (I was using Eclipse ADT before and never succeeded to integrate Gradle on it).

You can also directly compile your external jar files on Gradle by using:

compile fileTree(dir: 'libs', include: ['*.jar'])
Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85