Xamaring bindinglib project renames variable wrong

时间:2017-10-12 09:47:02

标签: c# xamarin xamarin.android

I have a problem in a binding lib. project, using Xamarin 4.6 in VC 2017.

In an .aar project I have following code:

public static final class ConformImage {
public static final int DO_NOT_CONFORM_IMAGE = 0;
public static final int CONFORM_IMAGE = 1;

    public ConformImage() {
    }
 }

Xamarin creats:

public sealed partial class ConformImage : global::Java.Lang.Object {

[Register ("CONFORM_IMAGE")]
public const int ConformImage = (int) 1;
...

The compiler is arguing that a Member is called like the class, "ConformImage". In my opinion xamarin renamed it wrong and created that problem.

Maybe anyone has an idea about that and could help me?

Thanks in advance.

1 个答案:

答案 0 :(得分:0)

在Java名称的C#规范化中,可能会发生名称冲突,可以通过Metadata.xml绑定项目中Xamarin.Android文件中的条目进行修复。

重命名该类或重命名const,您的选择:

重命名该类:

<attr path="/api/package[@name='your.java.package.name.here']/class[@name='ConformImage']" 
    name="managedName">ConformImageEx</attr>

重命名const:

<attr path="/api/package[@name='your.java.package.name.here']/class[@name='ConformImage']/field[@name='DO_NOT_CONFORM_IMAGE']" name="managedName"> DoNotConformThisImage </attr>
<attr path="/api/package[@name='your.java.package.name.here']/class[@name='ConformImage']/field[@name='CONFORM_IMAGE']" name="managedName">ConformThisImage </attr>

re:https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/customizing-bindings/

re:https://gist.github.com/JonDouglas/dda6d8ace7d071b0e8cb