0

I'm trying to use OWL API in Android in order to manage OWL ontologies. I've just started but my app stops working when instantiating the manager and the ontology. I'm using owlapi-distribution-4.1.4 and I added the jar file to the app/libs folder. I'd like to know how to solve this. I'm sure I'm missing something important, but since I'm new to this I can't spot it. There are some lines of my code:

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;  

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    File ontologyFile = new File("C:/Users/Acer/Documents/myOntology.owl");

    try {
        OWLOntology myOntology = manager.loadOntologyFromOntologyDocument(ontologyFile);
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }

I hope you will suggest me how to solve the problem. Thank you in advance!

paola91
  • 339
  • 1
  • 5
  • 14
  • What means stop working? You should get some message/error/exception. – UninformedUser Apr 10 '17 at 07:07
  • In my app there's a button that when clicked, should load the ontology. Well, when I click it the app closes with the message "The application stopped" in my smartphone. It doesn't show any exception or error messages, unfortunately... – paola91 Apr 10 '17 at 07:55
  • For sure there should be something in the android logs. – UninformedUser Apr 10 '17 at 08:27
  • Could you please tell me where to search for it? I'm using Android Studio 2.3.1 and there's nothing in the Android Monitor or in the debugger – paola91 Apr 10 '17 at 10:15

1 Answers1

1

Best guess is that you do not have all dependencies deployed in your lib. The owlapi jar it not enough by itself.

I'm not familiar with android studio but I assume it can add maven dependencies to a project? If not, I recommend using the dependencypack jar available in the releases project, it contains all required jar files and you can extract it in the lib folder easily enough.

Next thing to verify is that the absolute path for your input file works for your app. I'm guessing that might need changing as well.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • Hi, first of all thanks for your kind reply. I've followed your link and downloaded: - owlapi-dependencypack-4.3.1.jar - owlapi-distribution-4.3.1.jar I've put both jars in app/libs path. Also, I've added the modules to my project. In the build.gradle file there's the line compile fileTree(include: ['*.jar'], dir: 'libs') The app keeps crashing. What did I miss? Secondly, what do you exactly mean with the advice about the absolute path for my input file? – paola91 Apr 10 '17 at 13:52
  • 1
    The dependebcypack jar is an OSGi bundle: for android, do not use it as it is. Extract the jar files it contains (rename it to have extension .zip if that's easier). – Ignazio Apr 10 '17 at 14:14
  • About the path, you have a file in the C: drive - but your android app running on your phone won't be able to access that. It is likely that path will need to change as well to something the android app can access. – Ignazio Apr 10 '17 at 14:15
  • Ok, I extracted the owlapi-dependencypack-4.3.1.jar in the app/libs directory, now there's the related folder. Should I import in someway? Do I have to extract the other jars included in this path as well? It doesn't work yet, maybe I'm still missing something. About the path, are you talking about the ontology file? My app crashes when I create the manager, so before the loading of the .owl file, still, where should I place it? Does it need to be uploaded somewhere if I want to open it without the IRI? Thanks in advance – paola91 Apr 10 '17 at 18:25
  • The jars must be in the lib folder, not in any subfolder. Move them so you have lib/owlapi-distribution.jar, lib/guava.jar, and so on. – Ignazio Apr 10 '17 at 23:42
  • I've just tried it and it launches this exception: FAILURE: Build failed with an exception. ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE on these files: guice-4.1.0.jar guice-assistedinject-4.1.0.jar guice-multibindings-4.1.0.jar jackson-annotations-2.8.5.jar jackson-core-2.8.5.jar jackson-databind-2.8.5.jar – paola91 Apr 11 '17 at 18:36
  • I've tried to keep only the first file and removing others, the build is successful but the app keeps crashing. – paola91 Apr 11 '17 at 18:39
  • 1
    That won't work. The build is failing because all jars contain a file with the same name, but the build is attempting to unpack and merge them. That's not useful and will stop a number of libraries from being used in android. There must be a way around that, but it's an android thing and I can't help with that. – Ignazio Apr 11 '17 at 18:54
  • Ok, I managed to solve the issue about the exception. The main problem's still there. My question at this point is: is there a (previous) version of owlapi exists which has been used with android? I'm really struggling since all of this is for an important project, and I need to know if there's a baseline. – paola91 Apr 11 '17 at 20:31