Lottie 错误:“java.lang.IllegalStateException:无法解析组合”

Ton*_*ton 4 java android lottie

我试图将 LottieAnimationView 添加到项目中的 xml 布局中,但出现此异常:“java.lang.IllegalStateException:无法解析组合”。

\n
java.lang.IllegalStateException: Unable to parse composition\n    at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:78)\n    at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:71)\n    at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:95)\n    at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:88)\n    at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:158)\n    at com.airbnb.lottie.LottieTask.access$200(LottieTask.java:27)\n    at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:133)\n    at android.os.Handler.handleCallback(Handler.java:883)\n    at android.os.Handler.dispatchMessage(Handler.java:100)\n    at android.os.Looper.loop(Looper.java:237)\n    at android.app.ActivityThread.main(ActivityThread.java:7860)\n    at java.lang.reflect.Method.invoke(Native Method)\n    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)\n    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)\n Caused by: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Failed resolution of: Lokio/Okio;\n    at java.util.concurrent.FutureTask.report(FutureTask.java:123)\n    at java.util.concurrent.FutureTask.get(FutureTask.java:193)\n    at com.airbnb.lottie.LottieTask$LottieFutureTask.done(LottieTask.java:175)\n    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)\n    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)\n    at java.util.concurrent.FutureTask.run(FutureTask.java:271)\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)\n    at java.lang.Thread.run(Thread.java:919)\n Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lokio/Okio;\n    at com.airbnb.lottie.LottieCompositionFactory.fromRawResSync(LottieCompositionFactory.java:265)\n    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:234)\n    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:229)\n    at java.util.concurrent.FutureTask.run(FutureTask.java:266)\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)\xc2\xa0\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)\xc2\xa0\n    at java.lang.Thread.run(Thread.java:919)\xc2\xa0\n Caused by: java.lang.ClassNotFoundException: Didn't find class "okio.Okio" on path: DexPathList[[zip file "/data/app/com.create.loop-D3ZAa0jgAPGefDD0MoGI3A==/base.apk"],nativeLibraryDirectories=[/data/app/com.create.loop-D3ZAa0jgAPGefDD0MoGI3A==/lib/arm, /system/lib, /vendor/lib, /system/product/lib]]\n    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)\n    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)\n    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)\n    at com.airbnb.lottie.LottieCompositionFactory.fromRawResSync(LottieCompositionFactory.java:265)\xc2\xa0\n    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:234)\xc2\xa0\n    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:229)\xc2\xa0\n    at java.util.concurrent.FutureTask.run(FutureTask.java:266)\xc2\xa0\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)\xc2\xa0\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)\xc2\xa0\n    at java.lang.Thread.run(Thread.java:919)\xc2\xa0\n
Run Code Online (Sandbox Code Playgroud)\n

XML 布局的一部分:

\n
    <com.airbnb.lottie.LottieAnimationView\n    android:id="@+id/animationView"\n    android:layout_width="50dp"\n    android:layout_height="50dp"\n    app:layout_constraintBottom_toBottomOf="parent"\n    app:layout_constraintEnd_toEndOf="parent"\n    app:layout_constraintStart_toStartOf="parent"\n    app:layout_constraintTop_toTopOf="parent"\n    app:lottie_autoPlay="true"\n    app:lottie_loop="true"\n    app:lottie_rawRes="@raw/heart_beat" />\n
Run Code Online (Sandbox Code Playgroud)\n

有趣的是,当我创建一个新的测试项目并将上述代码粘贴到新创建的 Activity_main.xml 时,一切都在新项目中完美运行。

\n

我尝试app:lottie_rawRes="@raw/heart_beat"用app:lottie_fileName="heart_beat.json"(从资产文件夹)替换,但仍然没有结果。\n我该如何解决此问题?谢谢。

\n

小智 7

如果你只是想避免崩溃,你可以在设置动画之前设置lottie失败监听器而不是默认监听器。

lottieView.setFailureListener { t ->
    //do on error
}
lottieView.setAnimation(...)
Run Code Online (Sandbox Code Playgroud)