Coder Social home page Coder Social logo

Comments (10)

moljac avatar moljac commented on June 19, 2024

Why do you have both Android.Support and AnroidX?

if you reference both - of course you will have the same class twice.

1st solution - use FQClassNames (Fully Qualified), do not add both namespaces in using statements.

2nd solution - If some libraries that you use reference Android.Support - contact library authors/vendors and ask THEM to update their libs to AndroidX dependencies.

Under the hood is Jettifier tool used by google too. it should work on dependencies that are not migrated to AndroidX, but there are several exceptional cases (some libraries are known issue for Android java/kotlin developers).

BTW. Can you post here your source file (usings), please?

from androidx.

markmccaigue avatar markmccaigue commented on June 19, 2024

Hi, thanks for getting back to me.

As you say, it's not that we are taking a direct dependency on both Android.Support and AndroidX, but that some of our dependencies require AndroidX and some only have versions available with dependencies on Android.Support. I will get in touch with the vendors and request updates, but I'm hoping there is a way to have this project compile in the meantime.

I tried using fully qualified class names, but unfortunately this does not resolve things, I believe in this case that the class names exist in the same namespaces in both the Android.Support libraries and the AndroidX libraries. For example, I've checked in ILSpy and the MediaMetadataCompat type, for example, is in the Android.Support.V4.Media namespace in both assemblies.

It was my understanding that including the Xamarin.AndroidX.Migration package should allow us to proceed in this scenario, in the same manner as the Jettifier tool should.

Sure, I'll add an some example code below, thanks:

using Android.Support.V4.Media;
using Android.Support.V4.Media.Session;
using Com.Google.Android.Exoplayer2;
using Com.Google.Android.Exoplayer2.Ext.Mediasession;

namespace TheAppBuilder.Droid.BackgroundMedia
{
    public class MyQueueNavigator : TimelineQueueNavigator
    {
        public MyQueueNavigator(MediaSessionCompat mediaSession) : base(mediaSession)
        {
        }

        public override MediaDescriptionCompat GetMediaDescription(IPlayer player, int windowIndex)
        {
            var metadata = BackgroundAudioPlayerService.CurrentTrack;

            var builder = new MediaDescriptionCompat.Builder()
                     .SetMediaId(metadata.GetString(MediaMetadataCompat.MetadataKeyMediaId))
                     .SetTitle(metadata.GetString(MediaMetadataCompat.MetadataKeyDisplayTitle))
                     .SetSubtitle(metadata.GetString(MediaMetadataCompat.MetadataKeyDisplaySubtitle))
                     .SetDescription(metadata.GetString(MediaMetadataCompat.MetadataKeyDisplayDescription));

            var displayIconUri = metadata.GetString(MediaMetadataCompat.MetadataKeyDisplayIconUri);

            if (displayIconUri != null)
            {
                builder.SetIconUri(UriUtility.FromString(displayIconUri));
            }

            return builder.Build();
        }
    }
}

In this file, we have issues with the MediaDescriptionCompat, MediaMetadataCompat, and MediaSessionCompat.

from androidx.

moljac avatar moljac commented on June 19, 2024

@markmccaigue

thanks for getting back to me.

You're welcome. BTW no reason to thank me. Helping is the reason why we are here for.

It was my understanding that including the Xamarin.AndroidX.Migration package should allow
us to proceed in this scenario, in the same manner as the Jettifier tool should.

Not even google can solve all problems with jettifier. There are libraries which cause problems in java/kotlin world with AndroidX. And we add substantial amount of complexity on top of java/kotlin world.
Xamarin.AndroidX.Migration package works in most cases, but there could be problems for sure.

Is your code publicly open so I/we could check?

And: forget ExoPlayer and Player packages for now. They are quite complex to bind and I simply cannot gat some time to finish them. (I dislike to do <remove-node> during bindings).

from androidx.

moljac avatar moljac commented on June 19, 2024

Related (possible duplicate):

#62

from androidx.

moljac avatar moljac commented on June 19, 2024

Related (possible duplicate):

#62

@markmccaigue

Why not trying tips described here?

This is an issue we know about, but there may be a workaround:

Whole discussion:

#55

from androidx.

markmccaigue avatar markmccaigue commented on June 19, 2024

@moljac

Cool, that all makes sense. The code isn't open source, but I could probably put together a small reproduction app if you would like one?

I went through the workarounds in the issueyou linked. Removing and re-adding the assembly (first suggestion) resulted in different error messages:

'MyQueueNavigator.GetMediaDescription(IPlayer, int)': return type must be 'MediaDescriptionCompat' to match overridden member 'TimelineQueueNavigator.GetMediaDescription(IPlayer, int)'

The type 'MediaDescriptionCompat' is defined in an assembly that is not referenced. You must add a reference to assembly 'Xamarin.Android.Support.Media.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

The type 'MediaSessionCompat' is defined in an assembly that is not referenced. You must add a reference to assembly 'Xamarin.Android.Support.Media.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I suspect these might be due to the fact that I'm overriding a contract owned by a dependency that owns the references and points them at Support, but this is just a guess.

The good news is that the other workaround, of defining an extern alias, has indeed solved the issue! This seems to work fine on Visual Studio on Windows, however on Visual Studio for Mac there are visual errors highlighed, although the actual compilation completes with no problems.

In case anyone else runs into this issue the following is the target I added to the bottom of my Droid .csproj file:

<Target Name="AddCustomAliases" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'Xamarin.Android.Support.Media.Compat' AND '%(ReferencePath.NuGetPackageId)' == 'Xamarin.Android.Support.Media.Compat'">
        <Aliases>AndroidSupportMedia</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>

making the code file above:

extern alias AndroidSupportMedia;

using AndroidSupportMedia::Android.Support.V4.Media;
using AndroidSupportMedia::Android.Support.V4.Media.Session;
using Com.Google.Android.Exoplayer2;
using Com.Google.Android.Exoplayer2.Ext.Mediasession;

namespace TheAppBuilder.Droid.BackgroundMedia
{
    public class MyQueueNavigator : TimelineQueueNavigator
    {
        public MyQueueNavigator(MediaSessionCompat mediaSession) : base(mediaSession)
        {
        }

        public override MediaDescriptionCompat GetMediaDescription(IPlayer player, int windowIndex)
        {
            var metadata = BackgroundAudioPlayerService.CurrentTrack;

            var displayIconUri = metadata.GetString(MediaMetadataCompat.MetadataKeyDisplayIconUri);

            var builder = new MediaDescriptionCompat.Builder()
                     .SetMediaId(metadata.GetString(MediaMetadataCompat.MetadataKeyMediaId))
                     .SetTitle(metadata.GetString(MediaMetadataCompat.MetadataKeyDisplayTitle))
                     .SetSubtitle(metadata.GetString(MediaMetadataCompat.MetadataKeyDisplaySubtitle))
                     .SetDescription(metadata.GetString(MediaMetadataCompat.MetadataKeyDisplayDescription));

            if (displayIconUri != null)
            {
                builder.SetIconUri(UriUtility.FromString(displayIconUri));
            }

            return builder.Build();
        }
    }
}

from androidx.

moljac avatar moljac commented on June 19, 2024

@markmccaigue

Sorry for delay, but I wanted to release new set of AndroidX (Corona) updates, before I get back to issues and fixing 'em.

but I could probably put together a small reproduction app if you would like one?

Sure. you know the more samples we/I have - the better. We'll hit issues sooner, before they get to users (you). So,YES please.

Where did you find ExoPlayer bindings?

from androidx.

markmccaigue avatar markmccaigue commented on June 19, 2024

@moljac

Hey, also apologies for the delay. It might be some time before I can put together a repro, but I will get to it.

In the meantime, I'm using these ExoPlayer bindings :)

https://github.com/Baseflow/ExoPlayerXamarin

from androidx.

moljac avatar moljac commented on June 19, 2024

@markmccaigue
Thanks. I found it, but confirmation is great.
That ExoPlayer is not AndroidX version.

from androidx.

moljac avatar moljac commented on June 19, 2024

Closing this one, because it is stale.
Open new issue if the problem still persists.

from androidx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.