gindemit / unity-rlottie

Unity library that plays Lottie Animation to Texture2D
MIT License
165 stars 26 forks source link

Crash on Android builds #2

Closed NegaScout closed 2 years ago

NegaScout commented 2 years ago

There is a crash in Android build. I believe its because in LottieAnimationsPreview.cs on line 35 is used animationPreview.InitFromFile instead of initFromData. The filesystems on different platforms vary and in some (especially in Android) its not as straightforward to read/write files from native code.

Because the file paths and methods for reading files vary on every OS, I suggest to read the json on C# side and pass it to the rlottie call by rlottie::Animation::loadFromData.

The log from Android debug bridge is as follows:

2022/04/02 13:21:39.095 10606 10651 Error Unity InvalidOperationException: Failed to load file at path "jar:file:///data/app/com.DefaultCompany.LottiePlugin-01-bkWC_k3yCYRqTXfzUDg==/base.apk!/assets/jar:file:///data/app/com.DefaultCompany.LottiePlugin-01-bkWC_k3yCYRqTXfzUDg==/base.apk!/assets/alright_sticker.json", result: "ProtocolError" 2022/04/02 13:21:39.095 10606 10651 Error Unity at Support.StreamingAssets.StreamingAssetsHelper.LoadFileFromStreamingAssets (System.String streamingAssetsFilePath) [0x00000] in <00000000000000000000000000000000>:0 2022/04/02 13:21:39.095 10606 10651 Error Unity at Presentation.Utility.FilesHelper.CopyFileFromStreamingAssetsToPersistentData (System.String streamingAssetsFilePath, System.String targetFilePath) [0x00000] in <00000000000000000000000000000000>:0 2022/04/02 13:21:39.095 10606 10651 Error Unity at Presentation.Utility.FilesHelper.CopyAnimationsJsonsFromStreamingAssetsToPersistentData (System.String[] animations) [0x00000] in <00000000000000000000000000000000>:0 2022/04/02 13:21:39.095 10606 10651 Error Unity at Presentation.State.AppState.Awake () [0x00000] in <00000000000000000000000000000000>:0 2022/04/02 13:21:39.095 10606 10651 Error Unity

gindemit commented 2 years ago

Hey @wagneja4, I pushed a fix. The problem was in StreamingAssetsHelper implementation. It added the streaming assets folder to the final path twice. Please check out the latest version. There is another issue with UI in the first tab. I'll try to fix it now. You can open the second tab. It works good.