Can I somehow enable and use several versions of this .jar library?

I understand that this may seem absurd, but is it possible to drop two different versions of the .jar library into an Android project (where both versions obviously have identical or overlapping names of packages and classes) and somehow explicitly point to one of them when importing library classes in my own Java sources?

My development environment is Android Studio with Gradle.

My reason for considering this issue (if possible) is because I rely on a closed source jQuery driver library for the USB device that the Android application works with. The supplier added support for the latest chip versions in its latest driver, but at the same time refused to support older chip versions. This is a decision that they made for their own reason, and it is unlikely to be reversed. The idea that I have is to somehow transfer both old and new versions of the library in my application so that I can continue to support older equipment.

I suppose something like this would be theoretically possible, but a complicated thing, it might have taken one .jar to be decompiled, and the package names changed?

+5
source share
1 answer

To my surprise, I quickly succeeded using the jarjar utility, as suggested by CommonsWare.

The key to understanding how to do this was this QA:

Hand Change Jar to Change Package Names

I renamed one of my .jar using the guidelines above, and now they both sit side by side in my project.

I do not want to duplicate SO content, but for completeness I did the following:

Received latest version of jarjar .

Created a configuration file called rules.txt containing one line:

 rule uk.co.dog.** uk.co.cat.@1 

This is just an example. Given the .jar value with the uk.co.dog.* Package, dog will change to cat . Obviously change this to suit your actual case.

Then use the command line:

 java -jar jarjar.jar process rules.txt in.jar out.jar 

Where in.jar is the source of .jar and out.jar is transformed.

+6
source

All Articles