How to support multiple versions of a dependency (with breaking API changes)

Viewed 60

I'm developing a library for android, using AndroidStudio and distributed as an .aar

The library also interacts with another 3rd party library (thats optional)

So, until now, I was using a wrapper class, that checks for the 3rd party classes and implements a fallback behaviour if those are missing.

But recently that library introduced a new version with breaking API changes. I'd like to maintain the support compatibility with both versions of the 3rd party library. But I can't compile against both libraries at the same time.

Lets see a simplified example:

I was using the class com.thirdparty.Foo that way:

new Foo(context).run();

the new version of the library requires a call like this:

Foo.create(context).run();

By the way my best approach is to create two submodules in my project, one for the old dependency and one for the new one (declaring the 3rd party depenedencies inside the corresponding submodule's build.gradle)

And deciding in runtime what classes to call

But I don't know how to merge those submodules to be included inside the .aar.

Should I keep trying this way or should I implement another solution?

0 Answers
Related