How to use Flurry Analytics (.jar) in Xmarin.Android app?

I want to use Flurry in my Xamarin application. For this, I need to use Flurry Analytics for Android, which is a .jar file.

To do this, I created the Bindings Library and included FlurryAnalytics-4.2.0.jar as the InputJar. But after overvoltage I get this error:

Com.Flurry.Sdk.Eg' already defines a member called 'A' with the same parameter types

Indeed, the Binding Library generates two methods called "A" with the same parameters, but with different codes inside them.

Removing one of the manully methods does not work. Adding a special line to the Metadata.xml file can rename methods, but at least one of these methods is needed (I don’t know which one).

Does anyone know how I can solve this problem?

+4
source share
2 answers

Here is a ready-made solution, greetings!

class Flurry
{
    public const string ApiKeyValue = "YOUR_API_KEY";

    private readonly IntPtr _flurryClass;

    private readonly IntPtr _flurryOnStartSession;
    private readonly IntPtr _flurryOnEndSession;
    private readonly IntPtr _flurrySetContinueSessionMillis;

    public Flurry()
    {
        _flurryClass = JNIEnv.FindClass("com/flurry/android/FlurryAgent");

        _flurryOnStartSession = JNIEnv.GetStaticMethodID(_flurryClass, "onStartSession", "(Landroid/content/Context;Ljava/lang/String;)V");
        _flurryOnEndSession = JNIEnv.GetStaticMethodID(_flurryClass, "onEndSession", "(Landroid/content/Context;)V");
        _flurrySetContinueSessionMillis = JNIEnv.GetStaticMethodID(_flurryClass, "setContinueSessionMillis", "(J)V"); 
    }

    public void OnStartActivity(Activity activity)
    {
        try
        {
            JNIEnv.CallStaticVoidMethod(_flurryClass, _flurryOnStartSession, new JValue(activity), new JValue(new Java.Lang.String(ApiKeyValue)));
        }
        catch (Exception) { }
    }

    public void OnStopActivity(Activity activity)
    {
        try
        {
            JNIEnv.CallStaticVoidMethod(_flurryClass, _flurryOnEndSession, new JValue(activity));
        }
        catch (Exception) { }
    }

    public void setContinueSessionMillis(long millis)
    {
        try
        {
            JNIEnv.CallStaticVoidMethod(_flurryClass, _flurrySetContinueSessionMillis, new JValue(millis));
        }
        catch (Exception) { }
    }

}
+1
source

Flurry obfuscated their APIs, so all function names are A, B, C, AA, etc. Flurry uses the liberal use of inner classes. C # does not have inner classes. Xamarin fakes them, forcing them out of their encapsulation. This causes name conflicts.

The bright side is that we don’t need direct access to the vast majority of the Flurry library, so wrappers are not needed. I said to exclude the internals by adding the following to Metadata.xml in the Transforms folder.

<metadata>
  <remove-node path="/api/package[@name='com.flurry.sdk']" />
  <remove-node path="/api/package[@name='com.flurry.android.impl.ads']" />
</metadata>

This indicates the exclusion of these namespaces from the wrapper generator.

0
source

All Articles