RDF4J on Android?

239 views
Skip to first unread message

pmcb55

unread,
Dec 15, 2017, 4:30:48 AM12/15/17
to RDF4J Users
Hi,

A couple of weeks ago I asked this group about RDF4J running on Android, 'cos we couldn't get it working. We panicked a little, as it was a hackathon and so we just dropped RDF4J completely and hard-corded a solution.

But now I'm asking again from a more relaxed situation! Basically we get the following Error just on startup (i.e. while initialising Java statics), and with a minimum of RDF4J libraries (as per Bart's suggestion to limit our dependencies) - I don't have the list of dependencies here, but it was basically just Model, Utils and RIO with a couple of the serializers like Turtle and JSON-LD:

java.lang.Error: Could not instantiate javax.xml.datatype.DatatypeFactory

                                                               at org.eclipse.rdf4j.model.impl.AbstractValueFactory.<clinit>(AbstractValueFactory.java:56)

                                                               at org.eclipse.rdf4j.model.impl.SimpleValueFactory.getInstance(SimpleValueFactory.java:31)

                                                               at org.eclipse.rdf4j.rio.RDFFormat.<clinit>(RDFFormat.java:71)

                                                               at

…..

                                                            Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl" on path: DexPathList

 


We did come across this attempt to use RDF4J on Android (https://github.com/MM2-0/rdf4a), but it's inactive a year, and seems to be a full fork, which we'd rather not depend on.


Any help is greatly appreciated, as I'm a big fan of RDF4J :) !


Cheers,


Pat.


 


Bart Hanssens

unread,
Dec 15, 2017, 4:46:29 AM12/15/17
to RDF4J Users
Digging into some google issues and online forums, it seems that one is expected to include an implementation on Android

(https://developer.android.com/reference/javax/xml/datatype/DatatypeFactory.html
"Note that you must supply your own implementation (such as Xerces); Android does not ship with a default implementation."

It seems that downloading and the including Xerces jar might help


Best regards

Bart

james...@ontotext.com

unread,
Dec 15, 2017, 9:55:51 AM12/15/17
to RDF4J Users
Beyond the Xerces issues, I know that when running Java libraries on Android you also have to be careful about httpclient as this is already provided by Android and you cannot override it or change its version. The rdf4j-jsonld module is a little problematic as it depends on httpclient, commons-logging, and org.json all of which must match the version on Android exactly.

Can you share more about how you are setting up your project? Can you share a simple example project that we can try out?

Thanks,
James

Joshua Shinavier

unread,
Dec 15, 2017, 3:34:38 PM12/15/17
to rdf4j...@googlegroups.com
Here is an example of an Android app using RDF4j (Sesame, actually):


It is a little old, but it illustrates some of the hoops you may need to jump through. I did find it necessary to exclude httpclient.

Josh



--
You received this message because you are subscribed to the Google Groups "RDF4J Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdf4j-users+unsubscribe@googlegroups.com.
To post to this group, send email to rdf4j...@googlegroups.com.
Visit this group at https://groups.google.com/group/rdf4j-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdf4j-users/031d9099-87e2-463b-8e57-0c5086060eaa%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

pmcb55

unread,
Dec 18, 2017, 7:50:31 AM12/18/17
to RDF4J Users
Hi guys,

Thanks so much for the pointers!

@Bart - we did try to download our own Xerces and including it, but still hit the problem.

The developer who was looking into this is tied up now until at least Wednesday, but hopefully he'll get a chance to look at the other suggestions (and show our example setup for James to try out too!). He mentioned that he's had Xerces problems on Android before too, but never resolved them. Hopefully he'll find the time to get to the bottom of this one (in the meantime we'd planning on moving from native Android Java to JavaScript (i.e. React Native), so our RDF usage will move to a JavaScript library (probably rdflib))...

Cheers,

Pat.

Bart Hanssens

unread,
Dec 18, 2017, 10:56:09 AM12/18/17
to RDF4J Users
Hi Pat,

good luck with your app, whether it's RDF4J or JS-based :-)
Just in case, there is yet another ticket related to Android in the RDF4J issue tracker (https://github.com/eclipse/rdf4j/issues/435)

Best regards

Bart

pmcb55

unread,
Dec 21, 2017, 4:47:08 PM12/21/17
to RDF4J Users
Hi guys,

So we tried the ideas suggested, i.e. not using JSON-LD at all (even though we initially only wanted JSON-LD!), just to see if that really was the culprit. But removing it still fails with the same error.

We're not including any jsonld library, i.e. from the Gradle file:
compile 'org.eclipse.rdf4j:rdf4j-model:2.2.2'
compile 'org.eclipse.rdf4j:rdf4j-rio-api:2.2.2'
compile ('org.eclipse.rdf4j:rdf4j-util:2.2.2') {
exclude group:'com.google.guava'
}
compile 'org.eclipse.rdf4j:rdf4j-rio-turtle:2.2.2'


Here's the sample code I tried:
String exampleString = "@prefix mc: <http://data.companyy.com/vocab/> .\n" +
"@prefix w3w: <http://data.companyy.com/vocab/3rdparty/what3words#> .\n" +
"@prefix dbpedia: <http://dbpedia.org/resource/> .\n" +
"@prefix schema: <http://schema.org/> .\n" +
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" +
"\n" +
"\n" +
"<http://projectx.companyy.com/id/1> a schema:Person ;\n" +
" mc:coreProfile <http://projectx.companyy.com/id/1/profile/core> .\n" +
"\n" +
"<http://projectx.companyy.com/id/1/profile/core> a mc:CoreProfile ;\n" +
" schema:givenName \"Joe\" ;\n" +
" schema:familyName \"Bloggs\" ;\n" +
" schema:gender \"male\" ;\n" +
" schema:nationality dbpedia:Australia ;\n" +
" mc:maritalStatus \"Married\" ;\n" +
" schema:birthDate \"1990-01-01\"^^xsd:Date ;\n" +
" schema:birthPlace dbpedia:Sydney ;\n" +
" w3w:addr \"camp.road.tent1\" ;\n" +
" schema:spouse <http://projectx.companyy.com/id/67> .\n" +
"\n" +
"\n" +
"\n" +
"<http://projectx.companyy.com/id/67> a schema:Person ;\n" +
" mc:coreProfile <http://projectx.companyy.com/id/67/profile/core> .\n" +
"\n" +
"<http://projectx.companyy.com/id/67/profile/core> a mc:CoreProfile ;\n" +
" schema:givenName \"Jane\" ;\n" +
" schema:familyName \"Bloggs\" ;\n" +
" schema:gender \"female\" ;\n" +
" schema:nationality dbpedia:NewZealand ;\n" +
" mc:maritalStatus \"Married\" ;\n" +
" schema:birthDate \"1995-05-05\"^^xsd:Date ;\n" +
" schema:birthPlace dbpedia:Wellington ;\n" +
" w3w:addr \"camp.road.tent1\" ;\n" +
" schema:spouse <http://projectx.companyy.com/id/1> .";
InputStream stream = null;
try {
stream = new ByteArrayInputStream(exampleString.getBytes(StandardCharsets.UTF_8.name()));

final Model model = Rio.parse(stream, "", RDFFormat.TURTLE);
Log.d("test", "test");
} catch (Exception e) {
e.printStackTrace();
}

But got the same error:

Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found
                                                               at javax.xml.datatype.DatatypeFactory.newInstance(DatatypeFactory.java:106)
                                                               at org.eclipse.rdf4j.model.impl.AbstractValueFactory.<clinit>(AbstractValueFactory.java:53)
                                                               at org.eclipse.rdf4j.model.impl.SimpleValueFactory.getInstance(SimpleValueFactory.java:31) 
                                                               at org.eclipse.rdf4j.rio.RDFFormat.<clinit>(RDFFormat.java:71) 



On Friday, 15 December 2017 09:30:48 UTC, pmcb55 wrote:
Reply all
Reply to author
Forward
0 new messages