Java Binding: The type `…' does not exist in t

2019-05-18 06:16发布

问题:

I am trying to create a Xamarin Java Binding to the Spotify Android SDK. The SDK is now separated into two parts, one for authentication and one for the player. The former java binding works, however, the seconds gives me an error.

The original question was asked on the Xamarin Forums.


Hi,

I am trying to create a binding project for the Spotify Android SDK.

The SDK is seperated into two .aar files. One for authentication and one for media playback (Player). Firstly I tried having both .aar files in one Binding Project, but the Player.aar was ignored. However, moving it to its own seem to work.

Now, my issue is related to the Java Interface NativePlayerNotificationCallback which is generated to IPlayerNotificationCallback (hence the lack og Notification), but in the Player class it tried to implement: global::Com.Spotify.Android.Player.INativePlayerNotificationCallback.

I can find no other mention of INativePlayerNotificationCallback in the decompiled files. Only IPlayerNotificationCallback.

I understand that this is a bit difficult to imagine. Here are the java class files seen in JD-GUI:

The generated files are listed here:

Inside the file Com.Spotify.Sdk.Android.Player.IPlayerNotificationCallback.cs:

And the error message itself

Error CS0234: The type or namespace name INativePlayerNotificationCallback' does not exist in the namespaceCom.Spotify.Sdk.Android.Player'. Are you missing an assembly reference?

I would really appreciate any insight as to how I can get this to work. It looks to me like there are some inconsistencies in the naming of the interface, but I am not sure.

Thank you for helping out, Fredrik

回答1:

Should be fixed by adding metadata to Player binding project:

<metadata>
  <attr path="/api/package[@name='com.spotify.sdk.android.player']/interface[@name='NativePlayerNotificationCallback']" name="visibility">public</attr>
</metadata>

and Player class extension (into the Additions directory):

using System.Collections;
using Java.Lang;
using Java.Util.Concurrent;

namespace Com.Spotify.Sdk.Android.Player
{
    public partial class Player
    {
        public IList InvokeAll(ICollection tasks)
        {
            return null;
        }

        public IList InvokeAll(ICollection tasks, long timeout, TimeUnit unit)
        {
            return null;
        }

        public Object InvokeAny(ICollection tasks)
        {
            return null;
        }

        public Object InvokeAny(ICollection tasks, long timeout, TimeUnit unit)
        {
            return null;
        }
    }
}

You will probably need to implement these methods correctly by calling generic methods. Also I had to add metadata to Auth library binding project (I found it in your old topics) and referenced Auth project from Player project as it uses some of the classes (maybe that's no necessary).