gilzoide / unity-lottie-player

Player for Lottie animations, powered by rlottie, multithread/Job System-friendly
The Unlicense
24 stars 1 forks source link

DllNotFoundException on Android #8

Closed TonSharp closed 1 month ago

TonSharp commented 2 months ago

Hi! I am using Firebase Crashlytics to track crashes and non-fatals and I am observing the following issue. On many Android devices (especially on Samsung devices), the following exception occurs:

Non-fatal Exception: java.lang.Exception: DllNotFoundException: Unable to load DLL 'lottie-player'. Tried to load the following dynamic libraries: Unable to load dynamic library 'lottie-player' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "lottie-player" not found
at Gilzoide.LottiePlayer.RLottie.RLottieCApi.lottie_init(Gilzoide.LottiePlayer.RLottie.RLottieCApi)

With this stacktrace:

at Gilzoide.LottiePlayer.RLottie.RLottieCApi.lottie_init(Gilzoide.LottiePlayer.RLottie.RLottieCApi)
       at Gilzoide.LottiePlayer.RLottie.RLottieCApi..cctor(Gilzoide.LottiePlayer.RLottie.RLottieCApi.)
       at Gilzoide.LottiePlayer.NativeLottieAnimation..ctor(Gilzoide.LottiePlayer.NativeLottieAnimation.)
       at Gilzoide.LottiePlayer.LottieAnimationAsset.CreateNativeAnimation(Gilzoide.LottiePlayer.LottieAnimationAsset)
       at Gilzoide.LottiePlayer.ImageLottiePlayer.RecreateAnimationIfNeeded(Gilzoide.LottiePlayer.ImageLottiePlayer)
       at Gilzoide.LottiePlayer.ImageLottiePlayer.OnEnable(Gilzoide.LottiePlayer.ImageLottiePlayer)

What could be causing the issue with loading the library? And could the following link.xml file with the specified lines help in this case:

<linker>
    <assembly fullname="lottie-player" preserve="all"/>
</linker>
TonSharp commented 2 months ago

Also I've noticed that all the crashes are coming from the ARMv7 VFPv3 NEON processor. Maybe this will help to solve the problem

TonSharp commented 2 months ago

By the way the problem also applies to iOS builds, but unlike Android, here I observe crashes. Here some of theme:

          Crashed: Job.Worker 0
0  libsystem_platform.dylib       0x1c54 __bzero + 68
1  UnityFramework                 0x5db3a94 rlottie::internal::renderer::Composition::render(rlottie::Surface const&) + 924
2  UnityFramework                 0x5de3420 lottie_animation_render_aspect + 136
3  UnityFramework                 0x4d6d2e8 ExecuteJob(ManagedJobData*, void (*)(void*, void*, void*, void*, int), int, unsigned char*) + 1156 (JobsBindings.cpp:1156)
4  UnityFramework                 0x4d6c8fc ForwardJobToManaged(ManagedJobData*) + 1440 (JobsBindings.cpp:1440)
5  UnityFramework                 0x4d6a8b8 ujob_execute_job(ujob_control_t*, ujob_lane_t*, ujob_job_t*, ujob_handle_t, unsigned int) + 972 (ujobs.cpp:972)
6  UnityFramework                 0x4d6ab74 lane_guts(ujob_control_t*, ujob_lane_t*, int, int) + 1146 (ujobs.cpp:1146)
7  UnityFramework                 0x4d6b62c worker_thread_routine(void*) + 1157 (ujobs.cpp:1157)
8  UnityFramework                 0x4e3a0c8 Thread::RunThreadWrapper(void*) + 112 (Thread.cpp:112)
9  libsystem_pthread.dylib        0x3338 _pthread_start + 116
10 libsystem_pthread.dylib        0x1938 thread_start + 8
 Crashed: com.apple.main-thread
0  UnityFramework                 0x5de33c0 lottie_animation_render_aspect + 40
1  UnityFramework                 0x4d6d2e8 ExecuteJob(ManagedJobData*, void (*)(void*, void*, void*, void*, int), int, unsigned char*) + 1156 (JobsBindings.cpp:1156)
2  UnityFramework                 0x4d6d2e8 ExecuteJob(ManagedJobData*, void (*)(void*, void*, void*, void*, int), int, unsigned char*) + 1156 (JobsBindings.cpp:1156)
3  UnityFramework                 0x4d6c8fc ForwardJobToManaged(ManagedJobData*) + 1440 (JobsBindings.cpp:1440)
4  UnityFramework                 0x4d6a8b8 ujob_execute_job(ujob_control_t*, ujob_lane_t*, ujob_job_t*, ujob_handle_t, unsigned int) + 972 (ujobs.cpp:972)
5  UnityFramework                 0x4d6ab74 lane_guts(ujob_control_t*, ujob_lane_t*, int, int) + 1146 (ujobs.cpp:1146)
6  UnityFramework                 0x4d6a6bc ujob_wait_for(ujob_control_t*, ujob_handle_t, int) + 1711 (ujobs.cpp:1711)
7  UnityFramework                 0x4d6558c CompleteFenceInternal(JobFence&, WorkStealMode) + 50 (JobGroupID.h:50)
8  UnityFramework                 0x50b9b68 UI::Canvas::WaitOnBatchGeneration() + 286 (Jobs.h:286)
9  UnityFramework                 0x50ba06c UI::Canvas::RenderOverlays() + 1517 (vector:1517)
10 UnityFramework                 0x50c47e8 UI::CanvasManager::RenderOverlays(int) + 261 (CanvasManager.cpp:261)

This is not relates to the issue topic but also needs to be discussed

gilzoide commented 2 months ago

Hey @TonSharp, thanks for the report. Hmm, weird.

Also I've noticed that all the crashes are coming from the ARMv7 VFPv3 NEON processor. Maybe this will help to solve the problem

Well, the rlottie library does use NEON instructions, and it has even some assembly code for ARMv7 (specifically, the pixman code). I haven't tried this library on any ARMv7 devices, only ARM64, likely the build is wrong for this architecture, sorry about that 😔 I don't think I added this assembly to my amalgamated C++ code. I do have a spare Android device with an ARMv7 CPU, so I can try in it later.

gilzoide commented 2 months ago

This is not relates to the issue topic but also needs to be discussed

Then please create a new issue for it, so that we can discuss it properly.

TonSharp commented 1 month ago

Hi @gilzoide , is there any news about non fatals on android?

gilzoide commented 1 month ago

No, I haven't tried it yet. It's quite possible that fixing the build for armv7 including the assembly code will fix it, I'll try looking into it this week.

TonSharp commented 1 month ago

Okay, thank you. I hope the fix will help and I can integrate the new version in the next release of my app. Good luck!

gilzoide commented 1 month ago

Hey @TonSharp, I've confirmed that the problem was building without including the pixman arm neon assembly code. I had problems building it with the Android NDK 26, so instead I'm using a custom version of rlottie that just ignores the custom neon code when building with clang.

Tested the fix here in a real Android device with arm32 CPU, and it works now! I relased this fix as version 1.0.1, so you can update in your app. Please let me know if you still have problems after this.

Cheers \o/