Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin Java Binding Library multiple already defined errors ??

RedRaRedRa Member ✭✭✭

Hi all,

I have with issue that when I generate binding library for HERE-sdk.aar I got a lots of issues with multiple definitions:

  Com.Here.Sdk.Analytics.HEREAnalytics.cs(84, 20): [CS0102] The type 'HEREAnalytics.Options' already contains a definition for 'cb_getMap'
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(86, 20): [CS0111] Type 'HEREAnalytics.Options' already defines a member called 'GetGetMapHandler' with the same parameter types
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(93, 18): [CS0111] Type 'HEREAnalytics.Options' already defines a member called 'n_GetMap' with the same parameter types
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(220, 20): [CS0102] The type 'HEREAnalytics.Properties' already contains a definition for 'cb_getMap'
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(222, 20): [CS0111] Type 'HEREAnalytics.Properties' already defines a member called 'GetGetMapHandler' with the same parameter types
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(229, 18): [CS0111] Type 'HEREAnalytics.Properties' already defines a member called 'n_GetMap' with the same parameter types
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(322, 20): [CS0102] The type 'HEREAnalytics.Traits' already contains a definition for 'cb_getMap'
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(324, 20): [CS0111] Type 'HEREAnalytics.Traits' already defines a member called 'GetGetMapHandler' with the same parameter types
  Com.Here.Sdk.Analytics.HEREAnalytics.cs(331, 18): [CS0111] Type 'HEREAnalytics.Traits' already defines a member called 'n_GetMap' with the same parameter types

Seems like in this partial class already generated some where cb_getMap member, but I do not seem ...
I have found that it could be fixed somehow with Metadata.xml, but in documentation there is not topic regarding multiple definitions for member of class ...

Have anyone face with the same issue ? How yo solve it ?

Answers

  • RedRaRedRa Member ✭✭✭
    edited September 2020

    By some reason for such Java class:

    // HEREAnalytics.class
    public class HEREAnalytics {
        ...
        public static class Properties extends VariantMap<HEREAnalytics.Properties> {
            public Properties() {
            }
    
            public HEREAnalytics.Properties addHereKind(String var1) {
                this.put("hereKind", var1);
                return this;
            }
        }
        ...
    }
    
    // HEREAnalytics$Properties.class
    public class HEREAnalytics$Properties extends VariantMap<HEREAnalytics$Properties> {
        public HEREAnalytics$Properties() {
        }
    
        public HEREAnalytics$Properties addHereKind(String var1) {
            this.put("hereKind", var1);
            return this;
        }
    }
    

    Java Binding Library create two getter methods:

    public partial class Properties : global::Java.Lang.Object {
                static Delegate cb_getMap;
    #pragma warning disable 0169
                static Delegate GetGetMapHandler ()
                {
                    if (cb_getMap == null)
                        cb_getMap = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_GetMap);
                    return cb_getMap;
                }
    
                static IntPtr n_GetMap (IntPtr jnienv, IntPtr native__this)
                {
                    var __this = global::Java.Lang.Object.GetObject<global::Com.Here.Sdk.Analytics.HEREAnalytics.Properties> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
                    return global::Android.Runtime.JavaDictionary.ToLocalJniHandle (__this.Map);
                }
    #pragma warning restore 0169
    
    ...
    
                static Delegate cb_getMap;
    #pragma warning disable 0169
                static Delegate GetGetMapHandler ()
                {
                    if (cb_getMap == null)
                        cb_getMap = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_GetMap);
                    return cb_getMap;
                }
    
                static IntPtr n_GetMap (IntPtr jnienv, IntPtr native__this)
                {
                    var __this = global::Java.Lang.Object.GetObject<global::Com.Here.Sdk.Analytics.HEREAnalytics.Properties> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
                    return global::Android.Runtime.JavaDictionary.ToLocalJniHandle (__this.Map);
                }
    #pragma warning restore 0169
    }
    

    Seems like this happens due to that Java generates for static class additional separate class file HEREAnalytics$Properties.class ...
    But it is the general static Java class ... why Binding library cannot properly generate code for such simple scenario ?

    And how to fix this behavior ?

  • RedRaRedRa Member ✭✭✭

    Seems like it is pretty standard issue ...

    I have found similar issue https://forums.xamarin.com/discussion/91415/has-any-body-faced-with-inner-class-duplication-issue-during-aar-binding

    Seems like class-parser not properly analyze inner and nested classes ...

Sign In or Register to comment.