From Navit's Wiki
Jump to: navigation, search

Eclipse is a widely used and very flexible IDE to make coding more efficient. Of course, it can be used for developing Navit:



We will combine the usual CMake environment, which is used to configure the Navit build process and

Project Setup

We will set up Eclipse for out-of-source builds, meaning build artifacts get placed outside the source tree. This helps us keep the source tree clean in a similar way as cmake does, which makes version control a whole lot easier.

We assume that the source code for all your projects resides in ~/src and that you use ~/workspaces as the base directory for your Eclipse workspaces. Navit source code then goes in ~/src/navit and the project dir inside your workspace will be called navit-linux. This is not a must – you can use different path names, but remember to adapt the paths below.

  • Clone the git repo if you haven't already:
    • If you don't have commit rights:
    • If you have commit rights to the Navit repo:
      • cd ~/src
      • git clone
    • If you have your own fork of Navit, clone your own repo instead.
  • Start Eclipse with a new workspace, ~/workspaces/navit.
  • Prepare a project for a Linux build:
    • cd ~/workspaces/navit
    • mkdir navit-linux
    • cd navit-linux
    • cmake -G "Eclipse CDT4 - Unix Makefiles" ~/src/navit
  • Then, in your Eclipse workspace, do File > Import... > General > Existing Projects into Workspace
  • Check Select root directory and choose ~/workspaces/navit/navit-linux. Make sure Copy projects into workspace is not checked!

That's it! You can now build, run and debug Navit right from Eclipse.

Run Configurations

If you want to try out different command line options (e.g. run Navit with a different config file), you can do so by going to Run > Run Configurations... and creating a new run configuration.

Notes and Limitations

There are a few things to note, though:

  • To open source files for editing, browse for them under [Source directory]. The rest of the tree is either dynamically generated and should not be edited, or will point back to [Source directory]. Jumping to a declaration will always open the corresponding file from [Source directory], so you should do that too.
  • If you make any changes to your cmake setup (such as editing CMakeLists.txt or, they will not be picked up automatically by Eclipse. You need to update your project by following these steps:
    • cd ~/workspaces/navit/navit-linux
    • cmake -G "Eclipse CDT4 - Unix Makefiles" ~/src/navit
  • The Team features in Eclipse (accessing git right from the Eclipse UI) will not work because the source code is not part of the project directory. However, you can still use the git UI of your choice in the source dir.

Android Development

Android development is a bit more challenging than Linux development because we'll be dealing with two independent (but nested) source trees – the C code and the Android-specific Java code. You can see and edit the Java files with the above setup, but you'll get a lot of annoying error messages, and most of Eclipse's code analysis features won't work for the Java code.

This can be solved by importing the Java code as a separate project (which can go in the same workspace). Unfortunately we can't just import the whole thing as an Android project because Eclipse expects an AndroidManifest.xml file – which we can't provide because Navit's toolchain generates that file during build. But there's a workaround:

  • Make sure you have a workspace set up for Navit as described above.
  • In your workspace, do File > New > Android Application Project.
  • In the dialog that opens, make the following settings:
    • Application Name: Navit
    • Project Name: navit-android (again, you can choose a different name if you wish)
    • Package Name: org.navitproject.navit
    • Minimum Required SDK: 7
    • Target SDK: 19 (as of this writing)
    • Compile With: accept the default value
    • Theme: Holo Dark
  • Click Next and on the next page, make the following settings:
    • Create custom launcher icon: uncheck
    • Create activity: uncheck
    • Mark this project as a library: uncheck
    • Create Project in Workspace: check
  • Click Finish and you will get a new, still empty project.
  • Delete the src folder of your new project.
  • Do File > New > Folder. In the dialog that opens, click Advanced to reveal all options, then make the following settings:
    • Parent folder: navit-android (or whatever you chose as the project name above)
    • Folder name: src
    • Advanced options: Select Link to alternate location (Linked folder) and set the path to ~/src/navit/navit/android/src (we recommend browsing for the folder rather than entering the name directly).
  • Right-click the src folder and select Build path > Use as source folder from the menu
  • Restart Eclipse. (This step may not be necessary but during our tests Eclipse had trouble matching declarations to packages, resulting in features like Jump to Declaration and Call Hierarchy not working across source files. Restarting Eclipse fixed this.)

And you have the Android code in a separate project, with the usual syntax features available here.

Notes and Limitations

  • Open Java files from your Android project, not from the Linux one. (Those will work too and point to the exact same files, but syntax features will only work from the Android project.)
  • Team features (git integration) still won't work, so you'll have to stick with your external git UI.
  • Building from Eclipse probably won't work yet with this setup. You will still need to build your .apk from the command line as described in Android development#With cmake. (For convenience, you can create the respective build directory in your workspace dir.)

Potential Further Improvements

If anyone wants to have a go:

  • Delete the default libs and res from the project and instead link to their counterparts in the source dir, as we did with src above.
  • Delete the default AndroidManifest.xml and link to its counterpart in the cmake build dir for Android.
  • Figure out how to build an .apk from Eclipse. The above two are almost certainly prerequisites, as well as:
    • Having a cmake build dir for Android
    • Possibly linking further dirs from the Android build dir into the project (e.g. gen, bin)
    • Triggering a build of the native code with cmake (adding custom builders to the project)
    • Ensuring the APK builder picks up the native libraries we built (possibly accomplished by linking to the respective dirs)

Old instructions

The previous instructions were based on a different infrastructure (notably SVN) and took a slightly different approach. If you'd like to tinker, here they are:

Setup project

  • Start a new project, pick import SVN
  • Select C/C++ project
  • Choose now GNU Autotools(if there is nothing under toolchains install autotools(autoconf,automake/gettext) via your os packagemanager)
  • Open a terminal, switch to your workspace navit folder and invoke "cmake ./"
    • you now have makefile that matches your local setup
  • In Eclipse, pick "build all" and you should get a binary
  • Run as application and you your local build should start

Doing Navit/Android development with Eclipse INCOMPLETE

This guide assumes you already have the source downloaded locally, and have already built a package for Android using CMake (see Linux development).

  • Install Eclipse
    • Unzip to directory of your choice
    • Start Eclipse by going into your eclipse folder, and running eclipse
    • Setup a new workspace when prompted
  • Import Navit
    • File -> New -> Project...
    • Android -> Android Project
    • Next
    • Project Name: -> NavitProject
    • Create project from existing source
    • Location: browse to the directory navit/android/ within your cmake build directory.
    • Next
    • Build Target -> check Android 2.2
    • Next
    • Finish
    • Project -> Properties
    • Java Build Path from left hand window
    • Libraries tab
    • Add JARs
    • NavitProject -> libs -> TTS_library_stub.jar. OK
    • Java Compiler from left hand window
    • Apply on message window
    • Compiler compliance level: -> 1.6
    • OK
    • Yes

And then the project should be clean of errors besides the only one stating that android_layout_default.xml is not well-formed. That's sad true. That file is indeed not an xml document but a fragment of one. Do we have some setting to switch this check off? Should we rename that file?

Personal tools