简体   繁体   English

JScience测量单元库与android不兼容

[英]JScience unit of measurement library incompatible with android

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). 我的Android应用程序中有一个用例,需要保存数量,对其进行计算并以用户选择的单位(从预定义列表中)显示它。

JScience fit this need perfectly, but I cannot compile the application for Android due to the following error: JScience非常适合此需求,但是由于以下错误,我无法为Android编译应用程序:

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

I note that JSCience is powered by javolution. 我注意到JSCience由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. 这给了我两个选择:找到一个不同的库(我找到了JSR-363 API,但是除了SO响应中的链接所讨论的几个用例之外,我无法找到它的文档;例如,链接不讨论具体的单元类型以及在何处可以找到它们)或解决我在JScience和Android之间遇到的不兼容问题。

I will accept a solution that does either of those. 我将接受一种解决方案。

Not sure what else uses it, but this is caused by a double dependency of javolution. 不知道还有什么用,但这是由javolution的双重依赖引起的。 What you can do is in the build.gradle (Module app) file, you can exclude javolution when you include jscience. 您可以做的是在build.gradle(模块应用程序)文件中,当包含jscience时可以排除javolution。

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. 清理/重建项目,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM