LottieAlertDialog中DialogTypes.TYPE_CUSTOM无法解析问题咨询
报错原因
- 你引入的
com.github.mayuce:LottieAlertDialog:1.1版本中,DialogTypes枚举类未定义TYPE_CUSTOM字段,该字段是库后续版本新增的能力,1.1 版本暂不支持直接通过该枚举传入自定义 Lottie 文件。 - 你调用的三参数
Builder构造方法同样是高版本新增的 API,低版本库不存在对应方法签名,和你当前的依赖版本不匹配。
解决方案
提供两种可选择的处理方案:
方案一:升级依赖版本(推荐)
升级 LottieAlertDialog 到支持自定义动画参数的版本,同时配套升级 Lottie 基础库避免兼容性问题:
- 修改依赖配置为:
implementation 'com.airbnb.android:lottie:5.2.0' implementation 'com.github.mayuce:LottieAlertDialog:1.5'
- 同步 Gradle 依赖后,原有调用代码不需要修改即可正常运行。
方案二:沿用 1.1 版本,适配对应API
如果不想升级依赖版本,可以调整调用代码适配 1.1 版本的开放能力:
// 先使用现有枚举类型初始化Builder LottieAlertDialog.Builder builder = new LottieAlertDialog.Builder(this, DialogTypes.TYPE_INFO); // 调用setCustomAnimation方法设置自定义动画文件 builder.setCustomAnimation("lottie_file.json"); // 其他配置(标题、描述、按钮等)按需添加 LottieAlertDialog dialog = builder.build(); dialog.show();
附加排查项
如果修改后仍有编译异常,可依次执行以下操作:
- 检查自定义 Lottie 动画文件是否正确放置在
src/main/assets目录下 - 执行 Build -> Clean Project 后再执行 Rebuild Project,清除旧的编译缓存
内容的提问来源于stack exchange,提问作者Hadisyah
相关产品推荐
相关产品推荐

