binding: enum genarated with ValueOf and Values unknown return types

AndrewzAndrewz USMember ✭✭

The following Enum in Java:

            public enum FailureReason {
                /**
                 * A well formed response could not be retrieved from the Capture server
                 */
                INVALID_CAPTURE_API_RESPONSE,

                /**
                 * The Jump library has not been initialized
                 */
                JUMP_NOT_INITIALIZED,

                /**
                 * The user canceled sign-in the sign-in flow during authentication
                 */
                AUTHENTICATION_CANCELED_BY_USER,

                /**
                 * The password provided was invalid. Only generated by #performTraditionalSignIn(...)
                 */
                INVALID_PASSWORD,

                /**
                 * The sign-in failed with a well-formed Capture sign-in API error
                 */
                CAPTURE_API_ERROR,

                /**
                 * The sign-in failed with a JREngageError
                 */
                ENGAGE_ERROR
            }

And the generated C# in java binding library:

            public sealed partial class FailureReason : global::Java.Lang.Enum {

                internal static IntPtr java_class_handle;
                internal static IntPtr class_ref {
                    get {
                        return JNIEnv.FindClass ("com/janrain/android/Jump$SignInResultHandler$SignInError$FailureReason", ref java_class_handle);
                    }
                }

                protected override IntPtr ThresholdClass {
                    get { return class_ref; }
                }

                protected override global::System.Type ThresholdType {
                    get { return typeof (FailureReason); }
                }

                internal FailureReason (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {}

                static IntPtr id_valueOf_Ljava_lang_String_;
                [Register ("valueOf", "(Ljava/lang/String;)Lcom/janrain/android/Jump$SignInResultHandler$SignInError$FailureReason;", "")]
                public static global::Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason ValueOf (string p0)
                {
                    if (id_valueOf_Ljava_lang_String_ == IntPtr.Zero)
                        id_valueOf_Ljava_lang_String_ = JNIEnv.GetStaticMethodID (class_ref, "valueOf", "(Ljava/lang/String;)Lcom/janrain/android/Jump$SignInResultHandler$SignInError$FailureReason;");
                    IntPtr native_p0 = JNIEnv.NewString (p0);
                    global::Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason __ret = global::Java.Lang.Object.GetObject<global::Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason> (JNIEnv.CallStaticObjectMethod  (class_ref, id_valueOf_Ljava_lang_String_, new JValue (native_p0)), JniHandleOwnership.TransferLocalRef);
                    JNIEnv.DeleteLocalRef (native_p0);
                    return __ret;
                }

                static IntPtr id_values;
                [Register ("values", "()[Lcom/janrain/android/Jump$SignInResultHandler$SignInError$FailureReason;", "")]
                public static global::Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason[] Values ()
                {
                    if (id_values == IntPtr.Zero)
                        id_values = JNIEnv.GetStaticMethodID (class_ref, "values", "()[Lcom/janrain/android/Jump$SignInResultHandler$SignInError$FailureReason;");
                    return (global::Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason[]) JNIEnv.GetArray (JNIEnv.CallStaticObjectMethod  (class_ref, id_values), JniHandleOwnership.TransferLocalRef, typeof (global::Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason));
                }

            }

The ValueOf() and Values() methods return Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason instead of Com.Janrain.Android.Jump.SignInResultHandlerSignInError

How to fix this?

Posts

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    Could you post the entire metadata.xml? Also see my comment on your other, related thread - would be awesome if you could make a GitHub project out of it. That makes it easier for us to help you, and the end result will benefit all of us.

  • AndrewzAndrewz USMember ✭✭

    anyone?
    I've spent a lot of time on this issue...

    I don't understand why it generates those return types which do not exist (Com.Janrain.Android.ump.ISignInResultHandlerSignInError.FailureReason)

    I attached the generated C# code and the Android code which contains the enum.

    Also, I attached a file which contains some mappings which I do not understand

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    You're not giving us much to work with here..

    On preview and scanning through the actual JanRain source code, SignInResultHandler is an interface so the renaming to ISignInResultHandler seems logical to me.. What is the actual issue that you have?

    (not sure about the missing J from ump and the concatenated interfacename and classname, but would need to see the binding project for that)

  • AndrewzAndrewz USMember ✭✭
    edited May 2013

    the C# code (the first file, Com.Janrain.Android.Jump.cs.txt) code shows clearly that SignInResultHandlerSignInError is a class, and not an interface.

    It is the FailureReason enum which by some strange reason gets ValueOf() and Values() methods returning an nonexistent ISignInResultHandler in a nonexisting namespace (Com.Janrain.Android.ump.ISignInResultHandler )

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Yeah, the strange thing is that in the Java code, it IS an interface. So there is definitely something wrong here. Does this happen with an UNEDITED metadata.xml?

    If so, it might be best to post a bug report. And if your need is urgent and you're on a paid support plan, send an email the address listed on your account page.

  • AndrewzAndrewz USMember ✭✭

    OK here is the complete project.

  • AndrewzAndrewz USMember ✭✭
    edited May 2013

    any ideas?
    I spent 2 days already on this issue...

    The binding documentation does not help me. I have no idea why the C# Enum-derived class gets those methods returning a nonexistent interface. It doesn't look like there's anything I can do about that.
    I gave the complete source code of the binding project above, with the input Jar included.

    All errors refer to the same issue, with that non-existing interface being generated. Fixing that, will make the binding project compile.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭
    edited May 2013

    Okay so I've taken a look and actually tried creating the binding myself. I am running into the same issue as you. This is definitely a bug, please do make sure to file it.

    Looking at the JanRain source code, I can be kind of sympathetic. It is kind of a mess to deal with - static classes containing instance methods, embedded inside interfaces, which in turn are embedded inside a class. On top of that, enums that have dynamic fields added for no good reason. Yuck!

    The good news is that I did manage to get it at least building successfully, by a few small tweaks of Metadata.xml:

        <metadata>
      <attr path="/api/package[@name='com.janrain.android']/class[@name='Jump.SignInResultHandler.SignInError']/field[@name='reason']" name="type">SignInError</attr>
      <remove-node path="/api/package[@name='com.janrain.android']/class[@name='Jump.SignInResultHandler.SignInError.FailureReason']" />
      <attr path="/api/package[@name='com.janrain.android']/interface[@name='Jump.SignInResultHandler']/method[@name='onFailure']/parameter[1]" name="type">SignInError</attr>
      <attr path="/api/package[@name='com.janrain.android']/class[@name='Jump.State']" name="managedName">States</attr>
    </metadata>
    

    No errors after that! :-D But I have NOT tested the resulting .dll, I leave that up to you ;) I am definitely expecting additional weirdness, but it's a start at least.

  • AndrewzAndrewz USMember ✭✭
    edited May 2013

    Thanks, but by just adding an 'Android Application' to the solution and adding a reference to the binding library project, makes the app not compile because of 2 errors:

    Error   67   cannot find symbol
    symbol  : constructor SignInError()
    location: class com.janrain.android.Jump.SignInResultHandler.SignInError
    public class ISignInResultHandlerSignInError
        F:\Work\Projects\Xamarin\JanRainEngage\jump.android-master\jump.android-master\Jump\JanRainEngageBindings\TestApp\obj\Debug\android\src\com\janrain\android\ump\ISignInResultHandlerSignInError.java    4   8   TestApp
    
    
    Error   66   com.janrain.android.engage.JREngage.ConfigFinishListener has private access in com.janrain.android.engage.JREngage
            com.janrain.android.engage.JREngage.ConfigFinishListener
        F:\Work\Projects\Xamarin\JanRainEngage\jump.android-master\jump.android-master\Jump\JanRainEngageBindings\TestApp\obj\Debug\android\src\mono\com\janrain\android\engage\JREngage_ConfigFinishListenerImplementor.java   8   38  TestApp
    

    Again, this happens just by adding the library as reference, no code added in the created app.
    So weird..

    It's the 3rd day now, and I still can't move forward writing the app with Xamarin. I will wait few more days after and then probably give up. Without JanRain I cannot make the app for the client.

  • AndrewzAndrewz USMember ✭✭

    I recreated the library and app again using only the XML you posted for Metadata.xml
    Here's the only error I see when adding the library as reference

    Error   60   com.janrain.android.engage.JREngage.ConfigFinishListener has private access in com.janrain.android.engage.JREngage
            com.janrain.android.engage.JREngage.ConfigFinishListener
        F:\Work\Projects\Xamarin\JanRainEngage\Jump\JanRainEngageBindings\AndroidApplication3\obj\Debug\android\src\mono\com\janrain\android\engage\JREngage_ConfigFinishListenerImplementor.java   8   38  AndroidApplication3
    
  • AndrewzAndrewz USMember ✭✭

    I have another project which I wanted to start with using Xamarin.
    Seeing what kind of issues are with binding, I am really afraid to start.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    @Andrewz - it might be good to take a deep breath and relax a bit :) I know it's frustrating and you want this to work immediately but you might just have to roll up your sleeves a bit on this one. Please consider:

    • I invested some of my time to help you get the project building - this is at least a first step. As I said, additional issues are expected. But I am positive they can be solved.
    • The JanRain source code is.. well.. it does not look very healthy, let's put it that way. And this in turn makes creating a binding more complex than it would usually be.
    • Creating bindings always takes some human work and nearly always a bit of debugging, depending on the complexity of what it is you are binding. The end result however is your favorite third party library, usable in your favorite language.
    • If you get stuck and have a paid support plan, use that support. You have a client project, so I assume you can afford one. Otherwise you may just have to be a bit patient. People like me are just volunteering because we're nice guys/girls and like helping people out. But we do not work for Xamarin, so there are limitations to what we can do, and we do expect you to invest yourself fully into the problem you are sharing with us.
    • Xamarin is pretty mature, it's based on Monotouch and Monodroid and the Mono framework, and all of them have been around for a long long time and are used in a huge amount of apps. No need to doubt Xamarin as a platform just because you ran into an obstacle.

    If you absolutely positively cannot wait at all - contact Xamarin sales for paid coding support.

  • AndrewzAndrewz USMember ✭✭

    Chris, these are obscure issues. It's not like you can figure it out easily.
    I was extremely enthusiastic about Xamarin.

    But facing the issues with binding made me realize that whenever you need to use a third-party library (like JanRain) (and this happens alot in real apps) things start to get messy.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    Exactly, it's an obscure issue. And we are developers, we deal with obscure issues all the time. I've spent time around Appcelerator, Adobe AIR, Phonegap, etc etc. In my experience, Xamarin certainly does not have more issues than any of those. In fact, things seem a lot better with Xamarin - despite it being a far more powerful and complex platform..

    Binding in particular is a complex subject - on ANY platform. This is true for C++, Python, Ruby, Java, ANY situation where you are binding/briding two completely different languages. That's just logical. I would never expect binding to work fully automatically. Things are messy when you create bindings, especially when the library you are binding to is messy (as with JanRain). It's just a fact of life.

    True, in this instance you ran into a bug - and a significant one at that. That is bad luck. I do hope you have reported this bug in the meantime, and that it will be resolved soon. But the approach I suggested provides a workaround.

    And I do have to say - even though personally I do not have a lot of experience with creating binding projects for Android, and was completely unfamiliar with JanRain - even despite that, just based on the error feedback and the documentation, I was able to very quickly figure out a workaround there. I did not go any further than that, but continuing in the same fashion you should be able to get it done. Don't give up yet.

  • AndrewzAndrewz USMember ✭✭
    edited May 2013

    I was looking to your Metadata.xml
    You used 'name="type"' to change the type of the field.
    That is not in documentation. I spent a day trying to do that.
    Anyways, thanks for help.

  • AndrewzAndrewz USMember ✭✭

    by the way, I like your enthusiasm.
    I was enthusiastic too.
    Until I faced the binding thing and realized that when trying to use third-party libraries, it gets messy.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    You used 'name="type"' to change the type of the field. That is not in documentation.

    It is, right here. The binding documentation pages themselves only contain the new/additional Android-specific attributes, for the standard specifications they link to that GAPI doc.

    I do admit that I did not even look at that myself. I gleaned it from one of those binding sample projects I referred to earlier.

  • ChrisHonselaarChrisHonselaar NLBeta ✭✭✭

    by the way, I like your enthusiasm. I was enthusiastic too.

    Try to keep that enthusiasm alive :) Yes there are bumps, but there will also be 'oh, WOW' moments. I really do believe that C# and Xamarin.Android/.iOS/.Mac combined represent the state of the art.

    Ok, shutting up now - or Xamarin needs to start paying me ;)

Sign In or Register to comment.