Best way to include the dependencies in an Android library?

Viewed 170

I built a library that does some network requests with Retrofit. Retrofit is included in the library as a JAR file. I want to ship the library as .aar file.

The host app that will consume the .aar file will need to have Retrofit too since it needs to do some network requests.

What the host app should do?

  • Use the Retrofit library of the .aar file?

    I've tried that and is working, the problem is that doesn't sound like a maintainable solution since the host app will be tied to the Retrofit version inside the library.

  • Include another version of Retrofit?

    I've tried that and I'm getting errors when I compile the host app since I have multiple versions of the Retrofit files. e.g:

More than one file was found with OS independent path 'okhttp3/internal/publicsuffix/NOTICE'

  • Is there any other solution?

    I read that I can use the transitive option but if I do that the library will be dependent from the Retrofit version of the host app right?

1 Answers

Using the transitive option should be the best from my point of view.

The library is not dependent on the host app but the host app is dependent on the library. Your library will still use the version of Retrofit which you implemented inside the library.

By using the transitive option you are just making sure that the version of retrofit that is being used inside the Library is not being utilized by the host application.

Related