2

I am currently developing an Android application and I'd like to use Graphhoper 0.3 embedded in the application (I have no way of setting up a server). I am working with Android 4.0, Eclipse Kepler, Maven 3.2.1, Android for Maven Eclipse 1.0.1.

I first tried to pull branch 0.3 and set the "core" folder up as an Eclipse project, then adding it in the Build Path of my android project. I also tried to use the graphhopper-0.3-android.jar directly.

Android Project Main Activity onStart():

GraphHopper hopper = new GraphHopper().forMobile();

Unfortunately, everytime I got the following error:

java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory

It does not pop in a regular Java project; only in Android. I've tried to add the slf4j JAR's to the build path, with no success.

Any help would be greatly appreciated! It's my first post here, and I really don't know what I could try more. If you need any more information on my setup or anything, please ask!


Edit

Complete solution in comments of the validated answer.

Remy San
  • 525
  • 1
  • 4
  • 24
  • What errors did you have when adding library to build path? –  May 27 '14 at 08:37
  • If I add all the sfl4j JAR's given by the author in the build path, and exporting android, api, jdk14 and log4j12 with the project, I get this: Unable to execute dex: Multiple dex files define Lorg/slf4j/impl/StaticLoggerBinder; – Remy San May 27 '14 at 09:18

1 Answers1

0

Because you are trying to use Graphhopper directly, the Maven is not downloading all the dependencies of the Graphhopper. In order to fix this, you should either add the Graphhopper as Maven dependency, or try to resolve the dependencies 'by hand' - i.e. by adding missing classes to the build path and exporting them to the APK (if you are using Maven, then simply add the dependencies to the pom.xml without scope tag).

Albert Sadowski
  • 642
  • 5
  • 8
  • I though about that at first, but it works perfectly well when I create a GraphHopper instance in a regular Java project... Apart from the Graphhopper imported project, I was not using Maven. I am trying to configure a new Android project with Maven, and add the "graphhoper" dependency in it though. – Remy San May 27 '14 at 09:11
  • Maybe you have SLF4J on the path in your 'ordinary Java' runtime? For sure you don't have SLF4J on your device. Just add SLF4J as a dependency. – Albert Sadowski May 27 '14 at 09:15
  • I'll try it as soon as I resolved the error with "consume-aar", maven and ADT in Eclipse. Right now, I can not manage an Android Project using Maven in Eclipse. That's why I wanted to avoid it in the first place. – Remy San May 27 '14 at 09:56
  • Ok so finally worked! I used no IDE, just created a "android-quickstart" project from maven, and edited the files with a simple text editor to add my GraphHopper codeline and dependency. Next step is now to use an IDE... I will always have to build through Maven though. Thanks! – Remy San May 28 '14 at 07:07
  • Maybe try with Android Studio. Should cope with Maven seamlessly. – Albert Sadowski May 28 '14 at 07:09
  • That's what I was going for! – Remy San May 28 '14 at 07:11