Closed ahmed-shariff closed 4 years ago
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
This is the root cause - for some reason your Android runtime doesn't like this class file. Perhaps you'd need to tweak some compiler options, such as explicitly stating that the generated class files must conform to Java 1.8/Java 8.
Alternatively, don't use the class loader mechanism, and see if your Android runtime will throw a more meaningful exception in such a case:
com.mycompany.MyPMML
.PMML javaPmml = new com.mycompany.MyPMML();
Thank you for the support. I appreciate it alot.
So the problem seems to have been coming from the xercesImpl
library. Following this, I added
compile group: 'xerces', name: 'xercesImpl', version: '2.12.0'
to gradle, and now it loads.
So the problem seems to have been coming from the
xercesImpl
library.
That's seriously odd - the transpiled PMML class model object should be completely independent of the XML parsing/JAXB unmarshalling stack (for example, take a look at the generated Java source code - there are no XML imports anywhere).
If you have time, then you could invest some of it into investigating how exactly the Xerces library "contributes" to solving the original UnsupportedOperationException
. If there's an actual dependency hidden somewhere, then I'd sure like to eliminate it.
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
This is the root cause - for some reason your Android runtime doesn't like this class file. Perhaps you'd need to tweak some compiler options, such as explicitly stating that the generated class files must conform to Java 1.8/Java 8.
Alternatively, don't use the class loader mechanism, and see if your Android runtime will throw a more meaningful exception in such a case:
1. During transpilation, explicitly set the name of the generated class. For example, `com.mycompany.MyPMML`. 2. In your application, explicitly invoke the constructor of the above class:
PMML javaPmml = new com.mycompany.MyPMML();
@vruusmann Thank you
This has been an effective method for me. I was able to import the generated .jar file in my android project and run it successfully. One problem though. The app requires API level 26 and above because of this method, https://developer.android.com/reference/java/lang/ThreadLocal#withInitial(java.util.function.Supplier%3C?%20extends%20S%3E), used by jpmml-evaluator/model. Any workround for this? Need to suppport lower level API versions.
@atlantis0 I've extracted your comment into a separate issue (because it's not related to the original issue in any way).
Now, please can you go there, and provide a detailed Android SDK(?) complaint regarding this API incompatibility? Specifically, does it fail compile-time (the project doesn't build, because there's a chance of hitting the ThreadLocal#withInitial(Supplier)
method), or during run-time (the project builds fine, but the application fails when executed).
Can you "disable" the invocation of the default ThreadLocal#withInitial(Supplier)
method by setting a custom ThreadLocal
value manually?
Tell me more! Otherwise, my fix might be insufficient.
@atlantis0 Add your clarifications to https://github.com/jpmml/jpmml-model/issues/27
When I try to load a transpiled model from android, I get the following error:
I pushed the model file to android and ran the same code I used to execute it on the pc. The loading process I used: