Search code examples
javaandroidlottie

Lottie error: "java.lang.IllegalStateException: Unable to parse composition"


I am trying to add LottieAnimationView to my xml layout in my project but getting this exception: "java.lang.IllegalStateException: Unable to parse composition".

java.lang.IllegalStateException: Unable to parse composition
    at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:78)
    at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:71)
    at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:95)
    at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:88)
    at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:158)
    at com.airbnb.lottie.LottieTask.access$200(LottieTask.java:27)
    at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:133)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7860)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
 Caused by: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Failed resolution of: Lokio/Okio;
    at java.util.concurrent.FutureTask.report(FutureTask.java:123)
    at java.util.concurrent.FutureTask.get(FutureTask.java:193)
    at com.airbnb.lottie.LottieTask$LottieFutureTask.done(LottieTask.java:175)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)
 Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lokio/Okio;
    at com.airbnb.lottie.LottieCompositionFactory.fromRawResSync(LottieCompositionFactory.java:265)
    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:234)
    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:229)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:919) 
 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]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.airbnb.lottie.LottieCompositionFactory.fromRawResSync(LottieCompositionFactory.java:265) 
    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:234) 
    at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:229) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:919) 

Part of XML layout:

    <com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animationView"
    android:layout_width="50dp"
    android:layout_height="50dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:lottie_autoPlay="true"
    app:lottie_loop="true"
    app:lottie_rawRes="@raw/heart_beat" />

What is interesting is that when I created a new test project and paste the above code to the newly created activity_main.xml everything works perfectly in the new project.

I tried to replase app:lottie_rawRes="@raw/heart_beat" with app:lottie_fileName="heart_beat.json" (from assets folder) but still no result. How can I resolve this issue? Thank you.


Solution

  • Got it. In build.gradle(Module:app) I excluded 'okio' and 'okhttp' modules for some reason. That leaded to the exception.

    configurations {
        all*.exclude module: 'okhttp'
        all*.exclude module: 'okio'
    }