I have tried to use the Java map library mapsforge-vtm to show an offline map using a mapsforge file with Xamarin Android.
Within Visual Studio 2019, I created one aar binding project as "LibraryProjectZip" for the file "vtm-android-0.13.0.aar" and one jar binding project as "EmbeddedJar" for the file "vtm-android-0.13.0.jar".
There is also a dependency to "vtm-0.13.0.jar" which you can see in the file "vtm-android-0.13.0.pom".
That "vtm-0.13.0.jar" file seems to cause the problems (e.g. the java interface Gesture which I include further down below).
If you keep following the dependencies (by looking in the pom files), there are also dependencies to "slf4j-api-1.7.28.jar" and "androidsvg-1.4.jar" but those two jars do not seem to cause problems, as far as I can tell.
Regarding the problem file "vtm-0.13.0.jar" I have tried to use it as an "EmbeddedReferenceJar" within both of the above mentioned projects (i.e. the aar binding and the jar binding projects for vtm-android). Both of those two binding projects can build without errors (when also using "androidsvg-1.4.jar" and "slf4j-api-1.7.28.jar" as "EmbeddedReferenceJar"'s)
However, when trying to reference those projects from a Xamarin Android app, it does not work.
When trying to do that, I can not reference both the aar binding and the jar binding projects because then there is an error message about duplicated versions of for example the class "Org.Oscim.Android.MapView". But when I use only one of them (i.e. either aar or jar project), then only the types from the main libraries are available (i.e. the "LibraryProjectZip" file for "vtm-android-0.13.0.aar" and "EmbeddedJar" file for "vtm-android-0.13.0.jar").
But I seem to NOT be able to reference any types from the "EmbeddedReferenceJar".
For example, there is a java type "org.oscim.tiling.source.mapfile.MapFileTileSource" in the "vtm-0.13.0.jar" but it does not seem to become available i.e. I can NOT use:
using Org.Oscim.Tiling.Source.Mapfile.MapFileTileSource;
In fact, the only namespace I can use, starting with "Org.Oscim" is "Org.Oscim.Android" e.g. this works:
using Org.Oscim.Android;
Then I tried to create a separate "EmbeddedJar" from the file "vtm-0.13.0.jar", since I was hoping that it then could be referenced from Visual Studio. (and in that project I added "slf4j-api-1.7.28.jar" as "EmbeddedReferenceJar")
However, the compilation failed with 85 errors. And I have tried all four combinations of settings for "Android Class Parser" and "Android Codegen Target" (i.e. the four combinations of "class-parse + XAJavaInterop1" and "jar2xml + XAJavaInterop1" and "class-parse + XamarinAndroid" and "jar2xml + XamarinAndroid")
I have also tried with a couple of different target frameworks (Android 4.4 and Android 9 and Android 10).
50 of those 85 errors are this same error: Error CS0234 The type or namespace name 'IGesture' does not exist in the namespace 'Org.Oscim.Event' (are you missing an assembly reference?) vtm-jar ...\obj\Debug\generated\src\Org.Oscim.Event.IGesture.cs
Indeed, when looking in that file "IGesture.cs" there is no interface defined there. I had expected to find something like "public partial interface IGesture ..." in that file, in a similar way as there is a "public partial interface IGestureListener ..." in the file "IGestureListener.cs" in the same directory.
I suspect that it has something to do with the fact that the java interface "Gesture" seems to be a bit unusal and thus not being nicely supported by Xamarin/Visual Studio.
This is what I am talking about: Here is a "normal" kind of Java interface (GestureListener) which seems to work without errors in Visual Studio: https://github.com/mapsforge/vtm/blob/master/vtm/src/org/oscim/event/GestureListener.java
package org.oscim.event;
public interface GestureListener {
boolean onGesture(Gesture g, MotionEvent e);
}
Here is the source code for the problematic interface (Gesture) in "vtm-0.13.0.jar": https://github.com/mapsforge/vtm/blob/master/vtm/src/org/oscim/event/Gesture.java
package org.oscim.event;
public interface Gesture {
final class Press implements Gesture {
}
final class LongPress implements Gesture {
}
final class Tap implements Gesture {
}
final class DoubleTap implements Gesture {
}
final class TripleTap implements Gesture {
}
final class TwoFingerTap implements Gesture {
}
Gesture PRESS = new Press();
Gesture LONG_PRESS = new LongPress();
Gesture TAP = new Tap();
Gesture DOUBLE_TAP = new DoubleTap();
Gesture TRIPLE_TAP = new TripleTap();
Gesture TWO_FINGER_TAP = new TwoFingerTap();
}
As far as I can remember, I do not think I have ever seen that kind of Java code with classes being defined and instantiated within an interface. And I suppose that Xamarin/Visual Studio also have a hard time to understand that kind of Java code.
So, is there anything you can do about this (and all other build errors, totally 85, with this vtm library)?
Has anyone been able to implement an Android App with Xamarin Android that uses mapsforge-vtm bindings, including also having been able to put all the pieces together and succeeded to display a map from a mapsforge map file?