Bug 15005 - Trouble Binding Google Analytics for Mobile JAR ("already contains a definition for...")
Summary: Trouble Binding Google Analytics for Mobile JAR ("already contains a definiti...
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.8.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2013-09-26 00:06 UTC by Bill Dwyer
Modified: 2013-09-26 16:25 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Visual Studio Project File (1.20 MB, application/x-zip-compressed)
2013-09-26 00:06 UTC, Bill Dwyer
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Bill Dwyer 2013-09-26 00:06:42 UTC
Created attachment 4992 [details]
Visual Studio Project File

I am trying to bind to the GA for Mobile v3 library located here:

https://developers.google.com/analytics/devguides/collection/android/resources

Here is an error I am seeing on build:

Error 28 The type 'Com.Google.Tagmanager.Protobuf.AbstractMutableMessageLite' already contains a definition for 'cb_getDefaultInstanceForType'

When I search through the generated source folder for the term, "cb_getDefaultInstanceForType" I see a dozen different class files that each contain roughly the following:

static Delegate cb_getDefaultInstanceForType;
 #pragma warning disable 0169
 static Delegate GetGetDefaultInstanceForTypeHandler ()
 {
   if (cb_getDefaultInstanceForType == null)
   cb_getDefaultInstanceForType = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr>) n_GetDefaultInstanceForType);
   return cb_getDefaultInstanceForType;
 }

Every time there is a method that returns this delegate, it re-defines the delegate above the method. I realize that there is a way to remove certain things via the Metadata.xml file, but I am unclear how I would go about doing it for this circumstance.

I have attached my project where these errors can be reproduced in Visual Studio. Any help in the right direction would be greatly appreciated. Thanks!
Comment 1 Atsushi Eno 2013-09-26 00:51:21 UTC
If I remember correctly that is caused by Java generics erasure (we have limitation on Java generics support) and derivation with erased type parameter.

Instead of inspecting and resolving the exact issue that should be resolved in Metadata.xml (by the way it should be done against Java API, so specifying things like "delegate" never works), I created another Metadata.xml which is based on:

- the existing binding sample https://github.com/xamarin/monodroid-samples/AnalyticsV2
- the idea that only documented API should be considered for binding, which is only about com.google.analytics.tracking.android (according to SDK javadoc)


<metadata>
  <remove-node path="/api/package[@name!='com.google.analytics.tracking.android']" />
  <attr path="/api/package[@name='com.google.analytics.tracking.android']" name="managedName">Xamarin.GoogleAnalyticsV3.Tracking</attr>

  <!-- the Java class is derived from nonpublic type, which is not allowed in C# -->
  <attr path="/api/package[@name='com.google.analytics.tracking.android']/class[@name='GoogleAnalytics']" name="extends">java.lang.Object</attr>
  <!-- Java overrides protected method as public, which is not allowed in C# -->
  <attr path="/api/package[@name='com.google.analytics.tracking.android']/class[@name='CampaignTrackingService']/method[@name='onHandleIntent']" name="visibility">protected</attr>

  <!-- This special case binding change is required for Xamarin.Android internal -->
  <attr path="/api/package[@name='com.google.analytics.tracking.android']/class[@name='CampaignTrackingService']" name="extends">mono.android.app.IntentService</attr>
</metadata>

I could build the binding with this Metadata.xml.

Maybe I should push this as AnalyticsV3 sample in the repository above.
Comment 2 Bill Dwyer 2013-09-26 16:25:08 UTC
Thanks Atsushi! I agree that this could be valuable for those wanting to use Google Analytics v3 and might be wise to put it in the repo.