James Scott
James Scott

Reputation: 1230

Xamarin + Android + Binding YouTube video player compile errors

I'm looking to bind the YouTubeAndroidPlayerApi.jar into my Xamarin Android project. I've added the YouTubeAndroidPlayerApi.jar under my Jars folder, but my project won't compile.

Error: "Do not override object.Finalize. Instead use a destructor."

So I've tried to change the way it compiles by using an:

<attr path="/api/package[@name='Com.Google.Android.Youtube.Player']/class[@name='YouTubeThumbnailView']/method[@name='Finalize']" name="managedName">~YouTubeThumbnailView</attr>

In the Metadata.xml file under Transforms folder... It doesn't seem to change it to a finalizer though... I'm continuing to play around with the syntax here in hopes that I stumble across something that works.

Is this the right approach? Is there something else I could be doing that is a better solution? I'd really like some feedback.

Thanks!

Upvotes: 4

Views: 646

Answers (2)

gianlucaparadise
gianlucaparadise

Reputation: 1763

If you add the remove-node, you will remove the finalizer and the code under finalize method will never be called. If you want to re-use the finalize implementation in the destructor, you can add the following to your Metadata.xml file:

<!--  
    YouTubeThumbnailView class implemented a Java Finalizer. I have to implement a C# Destructor and call the finalize method.
    The C# Destructor is in the partial class under the Addition folder.
-->
<!-- I change the name of the finalizer method to avoid the conflict with java finalizer -->
<attr path="/api/package[@name='com.google.android.youtube.player']/class[@name='YouTubeThumbnailView']/method[@name='finalize' and count(parameter)=0]" name="managedName">InternalFinalize</attr>
<!-- I replace the protected override modifier with the internal modifier -->
<attr path="/api/package[@name='com.google.android.youtube.player']/class[@name='YouTubeThumbnailView']/method[@name='finalize' and count(parameter)=0]" name="visibility">internal</attr>

N.B. the visibility modifier is needed to remove the override modifier.

Then you should add the following class under the folder Additions:

namespace Com.Google.Android.Youtube.Player
{
    public partial class YouTubeThumbnailView
    {
        ~YouTubeThumbnailView()
        {
            this.InternalFinalize();
        }
    }
}

Upvotes: 0

Jon Douglas
Jon Douglas

Reputation: 13176

You should just be able to remove this fairly easily. However your issue in your <attr> is the fact that you have the incorrect package name/class name as it should follow Java convention(<lowercase package>.<propercase class>). Simply ensure the case like the example below:

EX:

<remove-node path="/api/package[@name='com.google.android.youtube.player']/class[@name='YouTubeThumbnailView']/method[@name='finalize' and count(parameter)=0]" />

Upvotes: 5

Related Questions