0

I just created a new library, Powerful Image View.
My library is a custom AppCompatImageView, so I need the appcompat-v7 library. And here comes the question:

How should I add it to my library?
Should I use 'compile', or 'provided' and let the user add the library to its own dependencies?
And how should i handle different versions of the libraries used, since i'm not depending on a specific version?

I added to the library's gradle file this line:

provided 'com.android.support:appcompat-v7:+'

I'd like to know your thoughts about this :)

Stefano Siano
  • 569
  • 1
  • 4
  • 13

1 Answers1

1

Should I use 'compile', or 'provided' and let the user add the library to its own dependencies?

I would use compile and make sure that the developer using your library understands that your library relies upon appcompat-v7, as that in turn places lots of other requirements (e.g., using AppCompatActivity, using Theme.AppCompat).

And how should i handle different versions of the libraries used, since i'm not depending on a specific version?

Well, you are requiring some version. AppCompatImageView does not exist in all versions of appcompat-v7. I recommend depending upon a concrete version (i.e., not +), ideally the latest-and-greatest version.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I see what you mean, but this also means that if the user uses a specific old version of the appcompat library, for any reason, he wouldn't be able to use it. And what about compile 'com.android.support:appcompat-v7:25.+' ? – Stefano Siano Apr 02 '17 at 13:43
  • 1
    @StefanoSiano: "this also means that if the user uses a specific old version of the appcompat library, for any reason, he wouldn't be able to use it" -- the developer can direct Gradle to use the old version. "And what about compile 'com.android.support:appcompat-v7:25.+' " -- I have been steering away from `+` in general. You do not really know if your code will work with arbitrary future versions of `appcompat-v7` without modification, and the developer can choose to use an older or newer `appcompat-v7` anyway. – CommonsWare Apr 02 '17 at 13:50