Closed Alexander-Mathew closed 3 months ago
we are seeing the issue
Also seeing this issue. So far, I've tried updating all of my AndroidX packages, but no luck.
Also seeing this issue. So far, I've tried updating all of my AndroidX packages, but no luck.
i think that is the issue here: updating the AndroidX nugets causes this issue
This comment is to follow this thread
Also seeing this issue. So far, I've tried updating all of my AndroidX packages, but no luck.
i think that is the issue here: updating the AndroidX nugets causes this issue
Yes, downgrading did the trick (sadly)
Also seeing this issue. So far, I've tried updating all of my AndroidX packages, but no luck.
i think that is the issue here: updating the AndroidX nugets causes this issue
Yes, downgrading did the trick (sadly)
@inimirpaz downgrading what to what version?
Also seeing this issue. So far, I've tried updating all of my AndroidX packages, but no luck.
i think that is the issue here: updating the AndroidX nugets causes this issue
Yes, downgrading did the trick (sadly)
@inimirpaz downgrading what to what version?
Version 1.12.0.1 (I have also rolled back Xamarin.Google.Dagger to 2.46.1.2 and Xamarin.Firebase.Messaging to 123.1.2.2)
Version 1.12.0.1
Xamarin.AndroidX.Collection ?
Version 1.12.0.1
Xamarin.AndroidX.Collection ?
I added based on the exception I got in the logger
Version 1.12.0.1
Xamarin.AndroidX.Collection ?
I added based on the exception I got in the logger
And that fixed it ? It did not on my side.
Version 1.12.0.1
Xamarin.AndroidX.Collection ?
I added based on the exception I got in the logger
And that fixed it ? It did not on my side. No
For others running into this, there is an alternative library that is maintained by the Xamarin team, supports both Xamarin Forms and MAUI and seems fairly regularly updated. It worked well for our Xamarin Forms project and we will use that instead.
https://github.com/mono/SkiaSharp.Extended (must use prerelease nugets as of now)
This article was helpful although it explains for MAUI: https://cedricgabrang.medium.com/implementing-lottie-animations-in-your-net-maui-application-62bd484af651
For others running into this, there is an alternative library that is maintained by the Xamarin team, supports both Xamarin Forms and MAUI and seems fairly regularly updated. It worked well for our Xamarin Forms project and we will use that instead.
https://github.com/mono/SkiaSharp.Extended (must use prerelease nugets as of now)
This article was helpful although it explains for MAUI: https://cedricgabrang.medium.com/implementing-lottie-animations-in-your-net-maui-application-62bd484af651
I think I tried it and reverted writing my own simple version, coz that one was buggy in some situations.
Also it was not using the latest version of Skottie.
That is for Xamarin. For MAUI, uncomment the maui commented code.
Note that it requires Fody PropertyChanged.
<PackageReference Include="SkiaSharp.Skottie" Version="2.88.6" />
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using SkiaSharp;
using SkiaSharp.Views.Forms;
using Xamarin.Essentials;
using Xamarin.Forms;
using Animation = SkiaSharp.Skottie.Animation;
namespace Skottie
{
/// <summary>
/// Display a lottie file
/// </summary>
/// <example>
/// <skottie:SkottieView Animation="plexus.json" HeightRequest="200" AnimationScale="3" AnimationCenterOffset="-30,0" />
/// </example>
public class SkottieView : SKCanvasView
{
Animation? animation;
Stopwatch sw = new ();
CancellationTokenSource cancelLoop = new();
private bool hasHandler = true; //For xamarin only. Set to false for maui.
public string Animation { get; set; } = null!;
public double AnimationScale { get; set; }
/// <summary>
/// After scale is applied
/// </summary>
public Point AnimationCenterOffset { get; set; }
public bool IsDebugging { get; set; }
private void OnAnimationChanged()
{
Stop(true);
if(string.IsNullOrWhiteSpace(Animation))
return;
using var animationStream = ResourceLoader.GetEmbeddedResourceStream(typeof(SkottieView).Assembly, Animation);
if (animationStream == null)
Console.WriteLine($"Can't find lottie animation resource '{Animation}'");
else if(SkiaSharp.Skottie.Animation.TryCreate(animationStream, out animation))
Start();
else
Console.WriteLine($"Can't load lottie animation referenced by resource '{Animation}'");
}
private void Stop(bool disposeAnimation = false)
{
cancelLoop.Cancel();
sw.Stop();
if(disposeAnimation)
{
animation?.Dispose();
animation = null;
}
}
private void Start()
{
if (animation != null && hasHandler && Parent != null && IsVisible)
{
animation.Seek(0, null);
sw.Restart();
var delayBetweenFrames = TimeSpan.FromSeconds(1.0 / animation.Fps);
cancelLoop.Cancel();
var c = cancelLoop = new ();
Task.Run(async () =>
{
while(!c.IsCancellationRequested)
{
await MainThread.InvokeOnMainThreadAsync(() =>
{
if (c.IsCancellationRequested)
return;
try
{
//mainthread required on iOS
if (IsVisible && Parent != null && hasHandler && animation != null) //re-test
InvalidateSurface();
}
catch (Exception e)
{
Console.WriteLine($"SkottieView crashed in update loop: {e.Message}");
}
});
try
{
await Task.Delay(delayBetweenFrames, c.Token).ConfigureAwait(false);
}
catch
{
//Ignore task cancelled
}
}
});
}
}
protected override void OnParentSet()
{
base.OnParentSet();
if (Parent == null)
Stop(true);
else
Start();
}
protected override void OnPropertyChanged(string? propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == nameof(IsVisible))
{
if(!IsVisible)
Stop();
else
Start();
}
}
//MAUI
// protected override void OnHandlerChanging(HandlerChangingEventArgs args)
// {
// base.OnHandlerChanging(args);
// hasHandler = args.NewHandler != null;
// var hadHandler = args.OldHandler != null;
//
// if (hasHandler && !hadHandler)
// Start();
// else if (!hasHandler && hadHandler)
// Stop();
// }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
base.OnPaintSurface(e);
var anim = animation;
if(anim == null)
return;
if(sw.Elapsed > anim.Duration)
sw.Restart();
anim.SeekFrameTime(sw.Elapsed);
//If IsDebugging="true", display a red solid background
e.Surface.Canvas.Clear(IsDebugging ? SKColor.Parse("FF0000") : SKColors.Transparent);
var rect = e.Info.Rect;
if (AnimationScale > 1 || !AnimationCenterOffset.IsEmpty)
{
var center = new SKPointI((rect.Right+rect.Left)/2, (rect.Top+rect.Bottom)/2);
rect = new (
(int)Math.Round(center.X - rect.Width * AnimationScale / 2 + AnimationCenterOffset.X* AnimationScale),
(int)Math.Round(center.Y - rect.Height*AnimationScale/2 + AnimationCenterOffset.Y* AnimationScale),
(int)Math.Round(center.X + rect.Width*AnimationScale/2 + AnimationCenterOffset.X* AnimationScale),
(int)Math.Round(center.Y + rect.Height * AnimationScale/2 + AnimationCenterOffset.Y* AnimationScale)
);
//e.Surface.Canvas.Scale();
}
anim.Render(e.Surface.Canvas, rect);
}
#region resource loader
static class ResourceLoader
{
static readonly ConcurrentDictionary<string, string[]> CacheAssemblyResourceNames = new ();
/// <summary>
/// Attempts to find and return the given resource from within the specified assembly.
/// </summary>
/// <returns>The embedded resource stream.</returns>
/// <param name="assembly">Assembly.</param>
/// <param name="resourceFileName">Resource file name.</param>
public static Stream? GetEmbeddedResourceStream(Assembly assembly, string resourceFileName)
{
if (assembly?.FullName == null || string.IsNullOrWhiteSpace(resourceFileName))
return null;
if (!CacheAssemblyResourceNames.TryGetValue(assembly.FullName, out var resourceNames))
{
resourceNames = assembly.GetManifestResourceNames();
CacheAssemblyResourceNames[assembly.FullName] = resourceNames;
}
var resourcePaths = (from x in resourceNames
where x.EndsWith(resourceFileName, StringComparison.CurrentCultureIgnoreCase)
orderby Math.Abs(resourceFileName.Length - x.Length)
select x
).ToList();
if (resourcePaths.Count != 1)
return null;
return assembly.GetManifestResourceStream(resourcePaths.First());
}
}
#endregion
}
}
Thanks for the feedback.
try explicitly adding Xamarin.AndroidX.Collection.Jvm
. It was bound 3 months ago and seems like google moved some classes to new maven artifact.
https://www.nuget.org/packages/Xamarin.AndroidX.Collection.Jvm
./generated/androidx.collection.collection-jvm/obj/Release/net7.0-android/generated/src/AndroidX.Collection.SparseArrayCompat.cs
./generated/androidx.collection.collection-jvm/obj/Release/net6.0-android/generated/src/AndroidX.Collection.SparseArrayCompat.cs
./generated/androidx.collection.collection-jvm/obj/Release/monoandroid12.0/generated/src/AndroidX.Collection.SparseArrayCompat.cs
Thanks for the feedback.
try explicitly adding
Xamarin.AndroidX.Collection.Jvm
. It was bound 3 months ago and seems like google moved some classes to new maven artifact.https://www.nuget.org/packages/Xamarin.AndroidX.Collection.Jvm
./generated/androidx.collection.collection-jvm/obj/Release/net7.0-android/generated/src/AndroidX.Collection.SparseArrayCompat.cs ./generated/androidx.collection.collection-jvm/obj/Release/net6.0-android/generated/src/AndroidX.Collection.SparseArrayCompat.cs ./generated/androidx.collection.collection-jvm/obj/Release/monoandroid12.0/generated/src/AndroidX.Collection.SparseArrayCompat.cs
Doesn't work for Lottie...
I'll need repro sample or at least list of PackageReference
s.
I'll need repro sample or at least list of
PackageReference
s.
Having the issue even with updated AppCompat package. Here are my references:
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Collection">
<Version>1.4.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx">
<Version>1.6.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
<PackageReference Include="Xamarin.AndroidX.AppCompat">
<Version>1.6.1.6</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.ConstraintLayout">
<Version>2.1.4.2</Version>
</PackageReference>
<PackageReference Include="MvvmCross">
<Version>8.0.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.CardView">
<Version>1.0.0.17</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.CoordinatorLayout">
<Version>1.2.0.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Fragment">
<Version>1.6.2.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Google.Android.Material">
<Version>1.7.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading">
<Version>2.4.11.982</Version>
</PackageReference>
<PackageReference Include="MvvmCross.Plugin.Color">
<Version>8.0.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Transformations">
<Version>2.4.11.982</Version>
</PackageReference>
<PackageReference Include="Xamarin.Kotlin.StdLib">
<Version>1.9.22</Version>
</PackageReference>
<PackageReference Include="Xamarin.Kotlin.StdLib.Common">
<Version>1.9.22</Version>
</PackageReference>
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk7">
<Version>1.9.22</Version>
</PackageReference>
<PackageReference Include="Square.OkHttp3">
<Version>4.9.3.2</Version>
</PackageReference>
<PackageReference Include="FastAndroidCamera">
<Version>2.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Analytics">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="Acr.UserDialogs">
<Version>7.2.0.564</Version>
</PackageReference>
<PackageReference Include="Realm">
<Version>5.1.2</Version>
</PackageReference>
<PackageReference Include="Plugin.CurrentActivity">
<Version>2.1.0.4</Version>
</PackageReference>
<PackageReference Include="MvvmCross.DroidX.RecyclerView">
<Version>8.0.2</Version>
</PackageReference>
<PackageReference Include="MvvmCross.Plugins.Fingerprint">
<Version>2.1.5</Version>
</PackageReference>
<PackageReference Include="Plugin.StoreReview">
<Version>3.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4">
<Version>1.0.0.15</Version>
</PackageReference>
<PackageReference Include="Square.OkHttp3.LoggingInterceptor">
<Version>4.4.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8">
<Version>1.9.22</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Work.Runtime">
<Version>2.7.1.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Preference">
<Version>1.2.0.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.MediaGallery">
<Version>1.0.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.ExifInterface">
<Version>1.3.7</Version>
</PackageReference>
<PackageReference Include="Karamunting.Android.Intuit.Sdp">
<Version>1.0.6</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Extensions">
<Version>2.2.0.15</Version>
</PackageReference>
<PackageReference Include="Obfuscar">
<Version>2.2.35</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xamarin.GooglePlayServices.Tasks">
<Version>118.0.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.GooglePlayServices.Maps">
<Version>118.2.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.GooglePlayServices.Auth">
<Version>120.3.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Firebase.Analytics">
<Version>121.1.1</Version>
</PackageReference>
<PackageReference Include="Plugin.FirebasePushNotification">
<Version>3.4.35</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Navigation.Common">
<Version>2.5.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Navigation.Runtime">
<Version>2.5.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.GooglePlayServices.Location">
<Version>120.0.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Google.Accompanist.FlowLayout">
<Version>0.28.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Google.Accompanist.SystemUIController">
<Version>0.28.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Google.Accompanist.Placeholder">
<Version>0.28.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Google.Accompanist.DrawablePainter">
<Version>0.28.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.WebKit">
<Version>1.5.0</Version>
</PackageReference>
<PackageReference Include="Com.Airbnb.Android.Lottie">
<Version>4.2.2</Version>
</PackageReference>
</ItemGroup>
I ran into this while building a binding library for the HelpScout SDK, which uses Lottie. Haven't found a solution.
Hi
Thanks for the feedback. Does anybody have minimal repro? It is release, so ti could be trimming. Is AOT turned on?
@jonathanpeppers Any ideas?
For the error:
Error processing method: 'AndroidX.Collection.SparseArrayCompat Com.Airbnb.Lottie.LottieComposition::get_Characters()' in assembly: 'Lottie.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.Collection.SparseArrayCompat**
What package contains AndroidX.Collection.SparseArrayCompat
? Is it missing?
This is a long thread, is there a different error I should be looking at?
I'm not using AOT. I'm dead in the water, so I'll start working on a minimal repro.
probably this closed issue solves it https://github.com/Baseflow/LottieXamarin/pull/399 But they don't deploy it yet
Try this gist:
https://gist.github.com/softlion/fad8ab6a37809e169d4fcc6b81b0f57b
I use it since a year.
Try this gist:
https://gist.github.com/softlion/fad8ab6a37809e169d4fcc6b81b0f57b
I use it since a year.
Doesn't help when you've got a dependency that uses Lottie.
This should be fixed with the latest version of Xamarin.AndroidX.Collection
:
https://www.nuget.org/packages/Xamarin.AndroidX.Collection/1.4.0.2
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
Xamarin Android 13
Description
While trying to release the application in Android after switching the target framework to 13 getting Lottie package error.
Microsoft.Extensions.Hosting3.1.10 Microsoft.Extensions.Http3.1.10 Microsoft.Identity.Client4.29.0 PlayCore1.8.0 Plugin.CurrentActivity2.1.0.4 Plugin.Permissions6.0.1 Xamarin.AndroidX.Browser1.5.0.3 Xamarin.AndroidX.AppCompat1.6.1.6 Xamarin.Firebase.Messaging123.3.1 Xamarin.Forms" Version="5.0.0.2622" /> Xamarin.AndroidX.AppCompat.Resources1.1.0.2 Xamarin.AndroidX.Legacy.Support.Core.Utils" Version="1.0.0.22" /> Xamarin.Essentials" Version="1.8.0" /> Newtonsoft.Json13.0.1 Xamarin.Forms.PancakeView2.3.0.759 Com.Airbnb.Android.Lottie4.2.2 SkiaSharp.Svg1.60.0 SkiaSharp.Views.Forms2.88.6 SkiaSharp.Extended1.60.0 Microsoft.AppCenter.Analytics4.2.0 Microsoft.AppCenter.Crashes4.2.0 Autofac6.1.0 Refractored.MvvmHelpers1.6.2 Acr.UserDialogs7.1.0.483 Rg.Plugins.Popup2.0.0.11 Xamarin.Forms.Visual.Material5.0.0.2622 Xamarin.Google.Dagger2.27.0 Xamarin.GooglePlayServices.Base118.2.0.4 Xamarin.AndroidX.RecyclerView1.3.2.1 Xamarin.AndroidX.Collection1.3.0.2 Xamarin.AndroidX.Migration" Version="1.0.10"
Relevant log output