Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding third party library dependencies to Android Library

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?

like image 321
Olga Konoreva Avatar asked Oct 31 '22 03:10

Olga Konoreva


1 Answers

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'])
like image 117
Yoann Hercouet Avatar answered Nov 08 '22 08:11

Yoann Hercouet