尝试创建 mapsforge/vtm 的 Xamarin Android 绑定 Java 库时出现错误。

huangapple 未分类评论56阅读模式
英文:

Errors when trying to create Xamarin Android binding Java Library for mapsforge/vtm

问题

我尝试使用Java地图库mapsforge-vtm在Xamarin Android中显示使用mapsforge文件的离线地图。

在Visual Studio 2019中,我创建了一个aar绑定项目,名称为“LibraryProjectZip”,针对文件"vtm-android-0.13.0.aar",以及一个jar绑定项目,名称为“EmbeddedJar”,针对文件"vtm-android-0.13.0.jar"

还存在一个对"vtm-0.13.0.jar"的依赖,您可以在文件"vtm-android-0.13.0.pom"中看到。

"vtm-0.13.0.jar"文件似乎引起了问题(例如,我在下面进一步包含的Java接口Gesture)。

如果您继续查看依赖项(通过查看pom文件),还存在对"slf4j-api-1.7.28.jar""androidsvg-1.4.jar"的依赖,但是这两个jar文件似乎并没有引起问题,据我所知。

关于问题文件"vtm-0.13.0.jar",我尝试将其作为“EmbeddedReferenceJar”在上述两个项目中使用(即为vtm-android的aar绑定项目和jar绑定项目)。
这两个绑定项目都可以在没有错误的情况下构建(同时使用"androidsvg-1.4.jar"和"slf4j-api-1.7.28.jar"作为"EmbeddedReferenceJar")。

然而,在尝试从Xamarin Android应用程序中引用这些项目时,它无法工作。

在尝试这样做时,我不能同时引用aar绑定和jar绑定项目,因为这会导致有关类"Org.Oscim.Android.MapView"重复版本的错误消息。
但是,当我只使用其中一个(即aar项目或jar项目)时,只有主要库中的类型可用(即"vtm-android-0.13.0.aar"的"LibraryProjectZip"文件和"vtm-android-0.13.0.jar"的"EmbeddedJar"文件)。

但是,我似乎无法引用"EmbeddedReferenceJar"中的任何类型。

例如,在"vtm-0.13.0.jar"中有一个名为"org.oscim.tiling.source.mapfile.MapFileTileSource"的Java类型,但似乎无法使用以下代码:

using Org.Oscim.Tiling.Source.Mapfile.MapFileTileSource;

实际上,我只能使用以"Org.Oscim"开头的一个命名空间,比如以下代码可行:

using Org.Oscim.Android;

然后,我尝试从文件"vtm-0.13.0.jar"创建一个单独的"EmbeddedJar",因为我希望可以从Visual Studio中引用它。
(在该项目中,我将"slf4j-api-1.7.28.jar"添加为"EmbeddedReferenceJar")

然而,编译失败了,出现了85个错误。
我尝试了"Android Class Parser"和"Android Codegen Target"的四种设置组合
(即"class-parse + XAJavaInterop1"、"jar2xml + XAJavaInterop1"、"class-parse + XamarinAndroid"和"jar2xml + XamarinAndroid"的四种组合)。

我还尝试了几种不同的目标框架(Android 4.4、Android 9和Android 10)。

其中有50个错误是相同的错误:
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

的确,当查看"IGesture.cs"文件时,其中没有定义接口。
我原本希望在那个文件中找到类似"public partial interface IGesture..."的内容,类似于同一目录中的文件"IGestureListener.cs"中的"public partial interface IGestureListener..."。

我怀疑这与Java接口"Gesture"的代码有关,它似乎有点不寻常,因此Xamarin/Visual Studio不支持得很好。

这就是我所谈论的内容:
以下是一种"正常"类型的Java接口(GestureListener),在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);
}

以下是在"vtm-0.13.0.jar"中有问题的接口(Gesture)的源代码:
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

<details>
<summary>英文:</summary>

I have tried to use the Java map library [mapsforge-vtm](https://github.com/mapsforge/vtm) to show an offline map using a mapsforge file with Xamarin Android.

Within Visual Studio 2019, I created one [aar binding](https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar) project as &quot;LibraryProjectZip&quot; for the file [&quot;vtm-android-0.13.0.aar&quot;](https://repo1.maven.org/maven2/org/mapsforge/vtm-android/0.13.0/vtm-android-0.13.0.aar) and one [jar binding](https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar) project as &quot;EmbeddedJar&quot; for the file [&quot;vtm-android-0.13.0.jar&quot;](https://repo1.maven.org/maven2/org/mapsforge/vtm-android/0.13.0/vtm-android-0.13.0.jar).

There is also a dependency to [&quot;vtm-0.13.0.jar&quot;](https://repo1.maven.org/maven2/org/mapsforge/vtm/0.13.0/vtm-0.13.0.jar) which you can see in the file [&quot;vtm-android-0.13.0.pom&quot;](https://repo1.maven.org/maven2/org/mapsforge/vtm-android/0.13.0/vtm-android-0.13.0.pom).

That &quot;vtm-0.13.0.jar&quot; 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 [&quot;slf4j-api-1.7.28.jar&quot;](https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.28/slf4j-api-1.7.28.jar) and [&quot;androidsvg-1.4.jar&quot;](https://repo1.maven.org/maven2/com/caverock/androidsvg/1.4/androidsvg-1.4.jar) but those two jars do not seem to cause problems, as far as I can tell.

Regarding the problem file &quot;vtm-0.13.0.jar&quot; I have tried to use it as an &quot;EmbeddedReferenceJar&quot; 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 &quot;androidsvg-1.4.jar&quot; and &quot;slf4j-api-1.7.28.jar&quot; as &quot;EmbeddedReferenceJar&quot;&#39;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 &quot;Org.Oscim.Android.MapView&quot;.
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 &quot;LibraryProjectZip&quot; file for &quot;vtm-android-0.13.0.aar&quot; and &quot;EmbeddedJar&quot; file for &quot;vtm-android-0.13.0.jar&quot;).

But I seem to NOT be able to reference any types from the &quot;EmbeddedReferenceJar&quot;.

For example, there is a java type &quot;org.oscim.tiling.source.mapfile.MapFileTileSource&quot; in the &quot;vtm-0.13.0.jar&quot; 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 &quot;Org.Oscim&quot; is &quot;Org.Oscim.Android&quot; e.g. this works:

using Org.Oscim.Android;


Then I tried to create a separate &quot;EmbeddedJar&quot; from the file &quot;vtm-0.13.0.jar&quot;, since I was hoping that it then could be referenced from Visual Studio.
(and in that project I added &quot;slf4j-api-1.7.28.jar&quot; as &quot;EmbeddedReferenceJar&quot;)

However, the compilation failed with 85 errors.
And I have tried all four combinations of settings for &quot;Android Class Parser&quot; and &quot;Android Codegen Target&quot;
(i.e. the four combinations of &quot;class-parse + XAJavaInterop1&quot;  and &quot;jar2xml + XAJavaInterop1&quot; and &quot;class-parse + XamarinAndroid&quot; and &quot;jar2xml + XamarinAndroid&quot;)

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 &#39;IGesture&#39; does not exist in the namespace &#39;Org.Oscim.Event&#39; (are you missing an assembly reference?)
	vtm-jar	...\obj\Debug\generated\src\Org.Oscim.Event.IGesture.cs
	
Indeed, when looking in that file &quot;IGesture.cs&quot; there is no interface defined there.
I had expected to find something like &quot;public partial interface IGesture ...&quot; in that file, in a similar way as there is a &quot;public partial interface IGestureListener ...&quot; in the file &quot;IGestureListener.cs&quot; in the same directory.

I suspect that it has something to do with the fact that the java interface &quot;Gesture&quot; 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 &quot;normal&quot; 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 &quot;vtm-0.13.0.jar&quot;:
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?

</details>


huangapple
  • 本文由 发表于 2020年4月7日 21:04:15
  • 转载请务必保留本文链接:https://java.coder-hub.com/61080693.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定