Forking gradle dependencies on Android

379 views Asked by At

I have not developed Android for a while and I am trying to do things right with the new features as the Gradle dependencies.

I am wondering what are the best practices when you need to modify one particular dependency for suiting you needs.

For example, let's say we have two libraries that extend the RecyclerView functionality by subclassing the Adapter:

Adapter --> AdapterA
Adapter --> AdapterB

Since Java does not support multiple inheritances, I guess the only way to make both libraries work together would consist on modifying one of them so the subclassing hierarchy looks like this:

Adapter --> AdapterA --> AdapterB

If I am correct and this is the way to go, what would then be the best way of modifying and integrating the library, here are the options I can think of:

  1. Fork on GitHub and use JitPack to add the forked-modified library
  2. Add library as a local module to the app and modify source

Please justify or suggest what is better and if there are any other alternatives to achieve this.

2

There are 2 answers

0
Malcolm On

I say just make a local module which depends on the other library and modify that. Don't forget to record which changes you've made. Ideally, you import the module as a separate commit in the VCS, and then you modify it in another commit.

This has the advantage that if you want to update the library, it will be fairly easy to do since all you have to do is copy over the source for the new version and then make the same modifications. However, if you take the other approach, then you'd also have to push all the changes to GitHub, which adds complexity, but little benefit unless you want to share your modifications with someone else.

7
ayvazj On

This seems like an unusual circumstance - Maybe an example would help
Also consider composition before resorting to forking libraries. https://en.wikipedia.org/wiki/Composition_over_inheritance

class YourAdapter {
    private AdapterA adapterA
    private AdapterB adapterB
}