Skip to content

Instantly share code, notes, and snippets.

@felipeska
Forked from brendanzagaeski/Metadata.xml
Created May 29, 2019 19:48
Show Gist options
  • Save felipeska/f0787ce5fa66ad42d06e0f8c245ca791 to your computer and use it in GitHub Desktop.
Save felipeska/f0787ce5fa66ad42d06e0f8c245ca791 to your computer and use it in GitHub Desktop.
Some Metadata.xml fixes for binding ADTECH Mobile (http://www.adtech.com/) in Xamarin.Android
<!-- This is an example of http://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding-a-java-library/troubleshooting-bindings/#Problem_Duplicate_custom_EventArgs_types
In this particular case, the conflicting definition is in
`Com.Adtech.Mobilesdk.Publisher.Vast.Player.ILinearAdPlayer`.
That interface also defines an "onError" method.
Error CS0102: The type
`Com.Adtech.Mobilesdk.Publisher.Vast.Player.ErrorEventArgs'
already contains a definition for `p0' -->
<attr path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.player']/interface[@name='VideoPlayerListener']/method[@name='onError' and count(parameter)=1 and parameter[1][@type='java.lang.Exception']]" name="argsType">VideoPlayerListenerOnErrorArgs</attr>
<!-- The automatically generated event handlers cause some trouble
here because there are three overloads of `onInvalidAdHandler`.
We can rename each overload to have a unique name. That way the
generated event handlers and EventArgs types will have different
names too, and there won't be any conflicts.
Error CS0102: The type
`Com.Adtech.Mobilesdk.Publisher.Vast.Reporting.IInvalidAdListenerImplementor'
already contains a definition for `OnInvalidAdHandler' -->
<attr path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.reporting']/interface[@name='InvalidAdListener']/method[@name='onInvalidAd' and count(parameter)=2 and parameter[1][@type='com.adtech.mobilesdk.publisher.vast.model.InLine'] and parameter[2][@type='com.adtech.mobilesdk.publisher.vast.reporting.VastErrorType']]" name="managedName">InvalidAdListenerOnInvalidAdInline</attr>
<attr path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.reporting']/interface[@name='InvalidAdListener']/method[@name='onInvalidAd' and count(parameter)=2 and parameter[1][@type='com.adtech.mobilesdk.publisher.vast.model.VastResponse'] and parameter[2][@type='com.adtech.mobilesdk.publisher.vast.reporting.VastErrorType']]" name="managedName">InvalidAdListenerOnInvalidAdVastResponse</attr>
<attr path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.reporting']/interface[@name='InvalidAdListener']/method[@name='onInvalidAd' and count(parameter)=4 and parameter[1][@type='com.adtech.mobilesdk.publisher.vast.model.InLine'] and parameter[2][@type='com.adtech.mobilesdk.publisher.vast.reporting.VastErrorType'] and parameter[3][@type='java.lang.Integer'] and parameter[4][@type='com.adtech.mobilesdk.publisher.vast.model.creatives.MediaFile']]" name="managedName">InvalidAdListeneronInvalidAdInlineFour</attr>
<!-- For some reason these interfaces are not accessible, even though
they seem to be marked "public." Even Java Android apps cannot
access them. I am not certain what this means or how it is
possible. But in any case it seems unlikely that these types need
bindings (considering that they aren't even usable directly in
Java), so the simplest solution is probably just to remove them.
### Additional details for reference
`javap` shows that interfaces do exist and are public:
```
$ javap -classpath adtech-mobile-sdk.jar com.adtech.mobilesdk.publisher.vast.player.AdPlayer.AdPodListener
Compiled from "AdPlayer.java"
public interface com.adtech.mobilesdk.publisher.vast.player.AdPlayer$AdPodListener {
public abstract void onAdPodStarted(com.adtech.mobilesdk.publisher.vast.AdType, com.adtech.mobilesdk.publisher.vast.model.AdGroup, int);
public abstract void onAdPodStopped(com.adtech.mobilesdk.publisher.vast.AdType, com.adtech.mobilesdk.publisher.vast.model.AdGroup);
public abstract void onAdPodProgress(com.adtech.mobilesdk.publisher.vast.AdType, com.adtech.mobilesdk.publisher.vast.model.AdGroup, int, int);
}
```
But strangely the `javap` output for the parent class does _not_
show these types:
```
$ javap -classpath adtech-mobile-sdk.jar -p com.adtech.mobilesdk.publisher.vast.player.AdPlayer | grep AdPodListener || echo "Not found"
Not found
```
### Error Messages
These error messages only appear when you try to build an app
that references the binding project. They are Java build errors
rather than C# build errors.
AdPlayer_AdPodListenerImplementor.java:8: error: cannot find symbol
com.adtech.mobilesdk.publisher.vast.player.AdPlayer.AdPodListener
^
symbol: class AdPodListener
location: class AdPlayer
AdPlayer_AdPodPlayerListenerImplementor.java(54,54): Error: error: cannot find symbol
com.adtech.mobilesdk.publisher.vast.player.AdPlayer.AdPodPlayerListener
^
symbol: class AdPodPlayerListener
location: class AdPlayer
AdPlayer_LandingPageListenerImplementor.java(54,54): Error: error: cannot find symbol
com.adtech.mobilesdk.publisher.vast.player.AdPlayer.LandingPageListener
^
symbol: class LandingPageListener
location: class AdPlayer
AdPlayer_LinearAdListenerImplementor.java(54,54): Error: error: cannot find symbol
com.adtech.mobilesdk.publisher.vast.player.AdPlayer.LinearAdListener
^
symbol: class LinearAdListener
location: class AdPlayer -->
<remove-node path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.player']/interface[@name='AdPlayer.AdPodListener']" />
<remove-node path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.player']/interface[@name='AdPlayer.AdPodPlayerListener']" />
<remove-node path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.player']/interface[@name='AdPlayer.LandingPageListener']" />
<remove-node path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.player']/interface[@name='AdPlayer.LinearAdListener']" />
<!-- This type is not public. The same error would appear when
attempting to use this interface in a Java Android app. So the
binding for this type will not be needed and can be removed.
MediaDownloadService_MediaDownloadListenerImplementor.java(65,65): Error: error: MediaDownloadListener is not public in MediaDownloadService; cannot be accessed from outside package
com.adtech.mobilesdk.publisher.vast.cache.MediaDownloadService.MediaDownloadListener -->
<remove-node path="/api/package[@name='com.adtech.mobilesdk.publisher.vast.cache']/interface[@name='MediaDownloadService.MediaDownloadListener']" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment