NoClassDefFoundError on API 23 and lower
PierreNomade opened this issue · 6 comments
Hi all,
We are using ucum library on an Android project.
But it appears that we can't start our app on API 23 and lower.
When we try it, we got this error :
java.lang.NoClassDefFoundError: tec.uom.se.function.RationalConverter
at tec.uom.se.AbstractUnit.divide(AbstractUnit.java:426)
at tec.uom.se.AbstractUnit.divide(AbstractUnit.java:69)
at tec.uom.se.unit.Units.<clinit>(Units.java:172)
Here is our gradle dependencies :
implementation 'systems.uom:systems-quantity:1.0'
implementation 'systems.uom:systems-common-java8:1.0'
implementation 'systems.uom:systems-unicode-java8:1.0'
implementation 'systems.uom:systems-ucum-java8:1.0'
Works perfectly on API 24 and higher.
Do you have any ideas of what could be the problem ?
Thank you !
On Android, that is an interesting question, do you try using it with Java or Kotlin? Possible that API 23 is not Java 8 compatible yet, then it would explain why.
While not completely clear either there is some evidence, Java 8 features may only work properly above Android API 24: https://stackoverflow.com/questions/35934528/does-java-8-work-on-android-api-24-and-above-or-you-can-use-in-lower-api
Thank you for the answer.
We are using Java.
Yes it seems that the problem is Java 8.
But is there a workaround to use ucum on API 23 and lower ?
I'm afraid UCUM was not done with the RI of JSR 363. I am not sure what the exact reason was, but I believe some of the classes made use of Java SE 8 right from the start. I can't say if that was ever used on Android, but Eclipse UOMo including version 0.7 offers a UCUM module with "late binding" so it uses the full ucum-essence.xml file with the whole UCUM spec but some operations have less compile-time type-safety. Would that help your use case? We have not fully mavenized UOMo 0.7 or above, not sure, if that's a problem e.g. if you build with Gradle?
Oh and if Kotlin was an option for you and your Android app, it seems Physikal had UCUM support ever since in its complete-units
module. As Kotlin bytecode seemed compatible even all the way back to Java 6 or 7, it is said to work on very old Android API levels. HTH?
Yes we are building our project with Gradle.
I think Kotlin could be an option, if it can allows us to have UCUM on lower API.
We are going to check this solution, thank you for the help !
Please let us know, if that works, you could ask @ejberry or @zjuhasz where they use Physikal on Android. I heard they do, but I don't know which devices or versions. A main reason UCUM was never used under the first RI is, that it relies on ResourceBundle for its formatting and parsing, something the 1.0 RI avoided because it's not available on Java ME Embedded. That's why backporting it could be cumbersome, so if Kotlin solves your problem, it would be good.