Xamarin Forms Android启动页Lottie 4.1解析组合失败求助
解决Xamarin Forms Android中Lottie 4.1的「Unable to parse composition」错误
你的xamarin.json文件必须设置特定的Build Action,当前设为None是错误的——这会导致Lottie无法定位并解析动画文件,正是触发Java.Lang.IllegalStateException的核心原因。
正确的设置步骤:
- 右键点击项目中的
xamarin.json文件 - 打开「属性」面板
- 将「生成操作」(Build Action)改为
AndroidAsset
修改完成后,清理并重建项目,再运行即可正常加载Lottie动画。
你的布局代码参考:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <com.airbnb.lottie.LottieAnimationView android:id="@+id/animation_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" app:lottie_loop="false" app:lottie_speed="2.0" app:lottie_fileName="xamarin.json" app:lottie_autoPlay="true"/> </LinearLayout>
内容的提问来源于stack exchange,提问作者JBD
相关产品推荐
相关产品推荐

