Reputation: 851
Is there a possibility to use a class from the JDK (1.7) instead of the Android SDK (ADK, API 23)?
A class I need to work with exists in the Android SDK (API 23) and in the JDK (1.7). By default the class from the ADK is used. However I want to used the class from the JDK.
In my case I want to use the DatatypeFactory.newInstance(factoryClassName, classLoader)
which is placed in the package javax.xml.datatype
in the JDK and the ADK.
Due to differences in the implementation i would like to use the class from the JDK instead of the ADK.
How can I use the class from the JDK instead of the class form the ADK?
Upvotes: 3
Views: 364
Reputation: 7620
You cannot do that. Not by simply switching the import statements anyway. Your code running on Android as its destination platform will not have access to Java SDK classes, therefore the code will fail to load the classes or it will load the Android version of the class with the exact same fully qualified name (which is your case).
If you want to use that specific implementation from Java SDK, you will have to make it available at the destination platform.
You have 2 options, but neither is good:
rt.jar
(~50MB) into your project. However that would create many potential problems, as Android SDK and Java SDK mirror some packages and classes and you could end up loading the wrong versions.
or
The correct solution however is to
I don't know what are your specific requirements, but I would wager that Android's implementation of this class is quite close to Java one. If you cannot achieve something by using Android SDK, try asking about that specific problem here, or search for 3rd party libraries which could achieve, what you need. Perhaps the solution is easier than you think.
Upvotes: 3