Majchrzak / Flurry-Unity-3D

Flurry iOS and Android plugin for Unity 3D.
MIT License
64 stars 33 forks source link

Exception when calling service.LogEvent(eventName, parameters); #5

Closed infosekr closed 9 years ago

infosekr commented 9 years ago

E/Unity (13383): Exception: JNI: Unknown signature for type 'Analytics.FlurryAndroid+DictionaryConverter' (obj = Analy tics.FlurryAndroid+DictionaryConverter) instance

Looks like it's having trouble handling a Dictionary<string,string> for the parameters parameter. LogEvent(eventName) seems to work (haven't seen my event on the flurry site yet)

afrokick commented 9 years ago

I have this issue too.

andreiciceu commented 9 years ago

It happens to me too!

rcstuber commented 9 years ago

I had this issue too. It seems like the Dictionary to HashMap Converter is not working properly (maybe some internal issue in JNI Bridge). I did a workaround, where I would create the AndroidJavaObject for the HashMap directly inside a function an return it, rather than using the DictionaryConverter instance and casting it.

Add this to your FlurryAndroid.cs

    private static AndroidJavaObject ConvertHashMap(Dictionary<string,string> dict)
        {
            AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap");

            IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", 
                                                             "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            object[] args = new object[2];
            foreach(KeyValuePair<string, string> kvp in dict)
            {
                using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key))
                {
                    using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value))
                    {
                        args[0] = k;
                        args[1] = v;
                        AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), 
                                                    method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
                    }
                }
            }
            return obj_HashMap;
        }

_and call it like below, replacing the calls in the Wrapper where _DictionaryConverter* is used now*

using(AndroidJavaObject attrs = ConvertHashMap(parameters)) 
{
    FlurryAgent.CallStatic<AndroidJavaObject>("logEvent", eventId, attrs, timed);
}

Seems to work for me. Note the Dictionary conversion is very similiar. The conversion code was taken from another - more outdated -Flurry Unity plugin (https://github.com/bearprada/flurry-unity-plugin), but it's essentially the same as from Mateusz.

UPDATE: Changed 'params' to 'attrs' in the call function as I forgot params was a reserved keyword in C#

infosekr commented 9 years ago

Thank you for this code, looks good. Just waiting for my event to show up on Flurry but it runs for me.

 On Friday, April 3, 2015 1:06 AM, rcstuber <notifications@github.com> wrote:

I had this issue too. It seems like the Dictionary to HashMap Converter is not working properly (maybe some internal issue in JNI Bridge). I did a workaround, where I would create the AndroidJavaObject for the HashMap directly inside a function an return it, rather than using the DictionaryConverter instance and casting it.Add this to your FlurryAndroid.cs private static AndroidJavaObject ConvertHashMap(Dictionary<string,string> dict) { AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")

        IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", 
                                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

        object[] args = new object[2];
        foreach(KeyValuePair<string, string> kvp in dict)
        {
            using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key))
            {
                using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value))
                {
                    args[0] = k;
                    args[1] = v;
                    AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), 
                                                method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
                }
            }
        }
        return obj_HashMap;
    }and call it like below, replacing the calls in the Wrapper where *DictionaryConverter** is used now*using(AndroidJavaObject params = ConvertHashMap(parameters)) 

{ FlurryAgent.CallStatic("logEvent", eventId, params, timed); }Seems to work for me. Note the Dictionary conversion is very similiar. The conversion code was taken from another - more outdated -Flurry Unity plugin (https://github.com/bearprada/flurry-unity-plugin), but it's essentially the same as from Mateusz.— Reply to this email directly or view it on GitHub.

Majchrzak commented 9 years ago

Fixed, there was an error with AndroidJavaObject inheritance.