Hello,
After a lot of headache, I have been able to build and run OsmAnd on Windows. Here are some notes I took while it was compiling, hope it helps others :)
There are part that still wouldn't work so I had to find workarounds. Someone should open a wiki page to explain everything and how it can be done on Windows easily, because it took me about 3 nights.
*Tools you will need*
Android SDK: Download them from the official website, using the Windows Installer:
http://developer.android.com/sdk/index.html#Other. Once installed, launch the SDK Manager to install the optionnal packages. Do not download the packages for Android 5.0.1 but the packages for Android 4.4.2 instead (OsmAnd is preconfigured for android-19 : SDK version 19). If you have an Android device, I would suggest you don't download their disk image (emulator) as it is completly terrible and slow. If you have a device, try debugging on your device via USB, you will lose a lot less time. If you need to use an emulator, try "Genymotion", I heard very good things about it.
Android ADB drivers: You will need the ADB drivers for your phone so that it is recognized via USB. To check if your device can be seen by your computer, open a "cmd", cd to "/sdk/platform-tools/" in the Android SDK and type "adb kill-server", then "adb start-server" then "adb devices". Your device should be listed there. Note that you need to set it to debug mode, see this tutorial
Eclipse Luna: Download the "Eclipse IDE for Java developers" from here :
http://www.eclipse.org/downloads/. Unzip it somewhere, then run eclipse.exe (no install). Then follow these instructions to install the Android Developer Tools:
*Downloading sources via repositories*
I tried following the instructions from the wiki:
But unfortunately, I tried running the "repo" tool from Cygwin and got into a lot of errors, mostly Python complaining about files not found in /cygdrive/, read online that it was a conflict with my local install of Python for Windows. Didn't find a solution so instead I downloaded the sources directly from Github. If you are trying to build OsmAnd to make pull request, I suggest you try to make the "repo" tool work because if you download the sources manually, you will not be linked to the repositories anymore, so no more code updates.
To check which repositories to download, you need to check out this file:
"repo sync" is supposed to go fetch those repositories and rename them. You can do it manually. For instance, for this one:
You need to go to:
Then pick the "legacy_1.9" branch from the dropdown menu
So that you go to:
Bottom-right corner, click Download zip, extract it in your workspace are rename the resulting folder to the corresponding "path" attribute, here "core".
Do that for all the repos, you will get repos "android", "core", "tools", "misc", "resources", "help".
I believe it should be possible to download the repos via a tool like egit (in Eclipse) or TortoiseGit or something but I am not so good at Git. If you have some advice, please post it.
*Import projects into Eclipse*
Now that you have the sources, open your Eclipse that you installed with the ADT tooling. point your Workspace to the folder containing all the repositories you just downloaded. If you want to change workspace location, go to File > Switch workspace.
Then right click panel on the left > Import project. A dialog window will open. Type "work" in the search field and select "Existing projects in Workspace". Browse to your workspace location and Eclipse will find a few projects. You only need "OsmAnd" and "SherlockBar".
*Compiling the native shared libraries*
This step is optionnal. Like someone else said, you can take the ones from the official build. Here is how:
Basically, get them from the APK, copy the 4 folders into /android/libs and Project > Clean in Eclipse
If you want to generate the .so files manually, you can eventually do it. Add a environment variable "ANDROID_SDK" pointing to your Android SDK install. Download the Android NDK from
https://developer.android.com/tools/sdk/ndk/index.html and add an env. variable "ANDROID_NDK" pointing to the Android NDK
Then you will need to run a .sh file so open Cygwin, cd to /android/OsmAnd/ and execute
(ndk-build.sh could work, I am not sure about the difference)
You might get a "Permission denied" message. If so, add rights by executing this command:
chmod -R 777 /cygdrive/e/Workspaces/Android/
E:\Workspaces\Android\ is the folder containing "android", "core", etc. Then execute the .sh file again. The .SO files will be created.
*JNI Compilation*
So far, Eclipse will be complaining about imports related to net.osmand.core.jni.* that cannot be found. And indeed, there is no corresponding source files. Turns out you have to generate them yourself.
Side note: JNI stands for Java Native Interface and allows OsmAnd to call some native code (C/C++), which are in the SO file you just copied or generated. It is used for native routing and native rendering. There is a Java part which is just a stub that calls the native function automatically but for some reason, it is not in the sources.
Turns out the scripts are not in the legacy_1.9 branch or OsmAnd-core but in the master branch. You will find a "wrappers" folder there:
Download the sources or fetch if via git, then temporarily rename the previous "core" repo in "_core" and rename the master branch as "core" or the script won't find the right files. You can then revert to th legacy_1.9 branch.
Add a "SWIG" env variable pointing to the swig.exe file
Open cygwin and change directory to core/wrapper/java/ then execute "./generate.sh"
I had many troubles with the file paths that were wrong (could not find core.swig using relative path in cygdrive, even tho it was there), had to edit the generate.sh manually to something like:
# Actually perform generation
$SWIG \
-java \
-package net.osmand.core.jni \
-outdir "E:\Workspaces\Android\core\wrappers\java/gen/java/net/osmand/core/jni" \
-o "E:\Workspaces\Android\core\wrappers\java/gen/cpp/swig.cpp" \
-DSWIG_JAVA \
-I"E:\Workspaces\Android\core\include" \
-c++ \
-v \
"E:\Workspaces\Android\core\core.swig"
If it all goes OK, it should generate java files in wrappers\java\gen\java\net\osmand\core\jni
Just copy the "jni" folder in your OsmAnd project in src/net/osmand/core and it should solve the import issues
*Other error messages*
A lot of things went wrong during these 3 sleepless nights, I am not sure if some are my fault, useless or bad manipulation on my side, here is a couple things that could help you. Note that a lot of errors disappear with a Eclipse restart or a Project > Clean
When launching the Android emulator, if you get the error "Unable to execute dex: Multiple dex files define define Lcom/google/protobuf/MessageLite$Builder;", you need to uncheck the Android Private Library, see
http://stackoverflow.com/a/16606378/808102
Error NoClassDefFound on gnu.trove.*. Not sure why but the lib was in the libs folder ("gnu-trove-osmand.jar"). I believe once I right clicked the project > Properties > Java Build Path and added the JAR manually to the build path (try the Order and Export tab as well). Then clean your project.
Unable to execute dex: GC overhead limit exceeded
Note that there has been a lot of trial-and-error for hours and didn't take note of all the cryptic errors I got so there might be more. If an administrator read this message, please open a Wiki page dedicated to building OsmAnd on Windows. There has been quite a few message about it on the Google Groups so it is not uncommon.
These instructions might be a good start, people could edit the Wiki page and add their advice to finally get a clear guide on how to build on Windows because at the moment, this is close to impossible.
Hope it helps !
Fabien