JScience unit of measurement library incompatible with android

274 views Asked by At

I have a use-case in my android application where I need to save a quantity, perform calculations on it, and display it in a unit of the user's choice (from a predefined list).

JScience fit this need perfectly, but I cannot compile the application for Android due to the following error:

Error: Program type already present: javolution.ContextTestSuite$1

I note that JSCience is powered by javolution. This leaves me with two options: find a different library (I've found the JSR-363 API but I have been unable to find documentation on it beyond a few use cases as discussed in the links in this SO response; for example, those links do not discuss the concrete unit types and where they can be found) or fix the incompatibility I have experienced between JScience and Android.

I will accept a solution that does either of those.

1

There are 1 answers

0
Mark D. On BEST ANSWER

Not sure what else uses it, but this is caused by a double dependency of javolution. What you can do is in the build.gradle (Module app) file, you can exclude javolution when you include jscience.

dependencies {
    implementation 'com.android.support:support-v4:28.0.0'
    ...
    implementation('org.jscience:jscience:4.3.1') {
        exclude group: "org.javolution"
    }
}

Clean/Rebuild Project and it should work.