From Navit's Wiki
Revision as of 08:44, 4 October 2017 by Naggety (talk | contribs)
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

Android developers: ADT used to be the standard tool for Android development on Eclipse. Since Google has moved to Android Studio, ADT is no loner maintained. Andmore is an Eclipse project based on ADT code. It is a near drop-in replacement for ADT (though ADT projects need to be converted once to work with Andmore, see the FAQ at

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, import the project to Eclipse
    • 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!
  • The default working directory to run the program is the project root directory, but navit is located in 'navit' subdirectory and it needs the working directory to be the same to run properly.
    • Go to Run > Run configurations... > Arguments
    • Select as working directory ${workspace_loc:navit-linux}/navit
  • If you get the error Gtk-WARNING **: cannot open display: when running
    • Go to Run > Run configurations... > Environment
    • Add the environment variable DISPLAY with value :0

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.

In order to complete all the steps, you need to build Navit once from the command line as described in Android development#With cmake. (For convenience, you can create the respective build directory in your workspace dir.) If you don't, you won't be able to complete all of the steps. You can skip them for the moment and do them once you have built Navit. Eclipse will still be able to make sense of the code, but you will have files in your workspace (such as AndroidManifest.xml) which have nothing to do with Navit.

Here's how to do it:

  • 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).
  • Repeat the same two steps for the libs and res, deleting the default folders and replacing each with a link to its counterpart in the source dir.
  • Right-click the src folder and select Build path > Use as source folder from the menu
  • Right-click the navit-android folder (or your project's root folder) and do New > File. 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)
    • File name: leave blank (will be filled in automatically)
    • Advanced options: Select Link to file in the file system and set the path to ~/src/navit/navit/android/AndroidManifest.xml.cmake (we recommend browsing for the folder rather than entering the name directly).
  • Repeat the same steps to replace the default AndroidManifest.xml with a link to navit/android/AndroidManifest.xml, which resides in your cmake build dir for Android. (This requires having built Navit once.)
  • Right-click AndroidManifest.xml, choose Properties and check the Derived option. (This will tell Eclipse to give you a warning when you try to edit the file.)
  • (Optional) Right-click AndroidManifest.xml.cmake and select Open With > Text Editor to tell Eclipse to open its own editor for the file instead of launching an external one.
  • 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.

Potential Further Improvements

If anyone wants to have a go: Figure out how to build an .apk from Eclipse. Prerequisites will likely include:

  • Creating a cmake build dir for Android and running cmake from the command line once
  • 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?