lottie-android: JSON Reader AssertionError when doInBackground (Android 7, 8)

Hi guys, in latest Lottie Android version (2.5.0) we are having several crashes at doInBackground() method. This crash is only happening on Android 7 and 8 versions.

Here is our animation preloading code:

class LottieAnimations {

    companion object {

        @JvmStatic
        var willyWaiting: LottieAnimation? = null
        var specialBonusCollectCoins: LottieAnimation? = null
        var specialBonusCollectGems: LottieAnimation? = null

        @JvmStatic
        fun load(context: Context) {
            fromAssetFileName(context, "animation/waiting_lottie/data.json") {
                it?.let { willyWaiting = LottieAnimation(it, "animation/waiting_lottie/images") }
            }

            fromAssetFileName(context, "animation/special_bonus_collect_coins/data.json") {
                it?.let { specialBonusCollectCoins = LottieAnimation(it, "animation/special_bonus_collect_coins/images") }
            }

            fromAssetFileName(context, "animation/special_bonus_collect_gems/data.json") {
                it?.let { specialBonusCollectGems = LottieAnimation(it, "animation/special_bonus_collect_gems/images") }
            }
        }
    }

}

Here is the StackTrace:

OS Version: 8.0.0 Device: Xperia X RAM Free: 38.5% Disk Free: 60.8%

#0. Crashed: AsyncTask #4 at android.os.AsyncTask$3.done(AsyncTask.java:353) 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:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) 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:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

Caused by java.lang.AssertionError at android.util.JsonReader.peek(JsonReader.java:363) at android.util.JsonReader.expect(JsonReader.java:308) at android.util.JsonReader.beginObject(JsonReader.java:293) at com.airbnb.lottie.parser.LottieCompositionParser.parse(SourceFile:42) at com.airbnb.lottie.LottieComposition$Factory.fromJsonSync(SourceFile:269) at com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground(SourceFile:22) at com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground(SourceFile:12) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

#0. Crashed: AsyncTask #4 at android.os.AsyncTask$3.done(AsyncTask.java:353) 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:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

#1. pool-2-thread-1 at java.lang.Object.wait(Object.java) at java.lang.Thread.parkFor$(Thread.java:2135) at sun.misc.Unsafe.park(Unsafe.java:358) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2101) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1132) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1087) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1147) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

#2. httpThread at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:375) at android.os.Looper.loop(Looper.java:225) at android.os.HandlerThread.run(HandlerThread.java:65)

#3. ConnectivityThread at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:375) at android.os.Looper.loop(Looper.java:225) at android.os.HandlerThread.run(HandlerThread.java:65)

#4. pool-3-thread-1 at java.lang.Object.wait(Object.java) at java.lang.Thread.parkFor$(Thread.java:2135) at sun.misc.Unsafe.park(Unsafe.java:358) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2059) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1120) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1087) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1147) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

Any ideas?

Tnx in advance

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 13
  • Comments: 52

Commits related to this issue

Most upvoted comments

We are having the same issues (Lottie 2.5.5) - only Android 8. So hope to find a fix soon.

Caused by java.lang.AssertionError
       at android.util.JsonReader.peek(JsonReader.java:363)
       at android.util.JsonReader.expect(JsonReader.java:308)
       at android.util.JsonReader.beginObject(JsonReader.java:293)
       at com.airbnb.lottie.parser.LottieCompositionParser.parse(LottieCompositionParser.java:42)
       at com.airbnb.lottie.LottieComposition$Factory.fromJsonSync(LottieComposition.java:276)
       at com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground(AsyncCompositionLoader.java:22)
       at com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground(AsyncCompositionLoader.java:12)
       at android.os.AsyncTask$2.call(AsyncTask.java:333)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)

I’m aware this is probably an Android issue (not Lottie) but perhaps you could add an option of wrapping this in a try-catch block or something so not the whole app crashes when this happens?!

We don’t use lottie-android, but see a similar crash in our app:

Fatal Exception: java.lang.AssertionError
       at android.util.JsonReader.peek(JsonReader.java:363)
       ...

So far we only observed crashes on devices with 8.0.0 and 8.1.0. I currently assume it is a bug in JsonReader, so I opened a bug report here: https://issuetracker.google.com/issues/79920590

same error happens to me after I upgraded lottie from 2.3.0 to 2.5.0, mostly on Android 8.0 and some on Android 7.x

@Cdik I’ve tested it. It might help a lot, but not in 100% of the times. Written about it here:

https://github.com/airbnb/lottie-android/issues/1298#issuecomment-512686118

androidasset

Can you tell me where to set the build action? I didn’t find anywhere to set. Thanks a lot.

@1wayticket , what do you mean by build action? The .json file needs to go in app>src>main>assets

I met the same problem in Android8.0.0,荣耀BND AL10,but i don’t know how to fix it.

1 java.lang.IllegalStateException:Unable to parse composition

2 com.airbnb.lottie.LottieAnimationView$2.void onResult(java.lang.Throwable)(LottieAnimationView.java:68) 3 … 4 java.lang.AssertionError: 5 android.util.JsonReader.peek(JsonReader.java:363) 6 android.util.JsonReader.expect(JsonReader.java:308) 7 android.util.JsonReader.beginObject(JsonReader.java:293) 8 com.airbnb.lottie.parser.LottieCompositionParser.com.airbnb.lottie.LottieComposition parse(android.util.JsonReader)(LottieCompositionParser.java:42) 9 com.airbnb.lottie.LottieCompositionFactory.com.airbnb.lottie.LottieResult fromJsonReaderSync(android.util.JsonReader,java.lang.String)(LottieCompositionFactory.java:229) 10 com.airbnb.lottie.LottieCompositionFactory.com.airbnb.lottie.LottieResult fromJsonInputStreamSync(java.io.InputStream,java.lang.String,boolean)(LottieCompositionFactory.java:163) 11 com.airbnb.lottie.LottieCompositionFactory.com.airbnb.lottie.LottieResult fromJsonInputStreamSync(java.io.InputStream,java.lang.String)(LottieCompositionFactory.java:157) 12 com.airbnb.lottie.LottieCompositionFactory.com.airbnb.lottie.LottieResult fromRawResSync(android.content.Context,int)(LottieCompositionFactory.java:129) 13 com.airbnb.lottie.LottieCompositionFactory$2.com.airbnb.lottie.LottieResult call()(LottieCompositionFactory.java:116) 14 com.airbnb.lottie.LottieCompositionFactory$2.java.lang.Object call()(LottieCompositionFactory.java:114) 15 java.util.concurrent.FutureTask.run(FutureTask.java:266) 16 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 17 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 18 java.lang.Thread.run(Thread.java:764)

I’m seeing the same issue on 8.0.0 / 8.1.0 with Lottie 2.6.0-beta19 / 2.7.0.

java.lang.AssertionError com.airbnb.lottie.LottieAnimationView$2.onResult(Unknown Source:5)

1 java.lang.IllegalStateException:Unable to parse composition 2 com.airbnb.lottie.LottieAnimationView$2.onResult(Unknown Source:5) 3 ...... 4 Caused by: 5 java.lang.AssertionError: 6 android.util.JsonReader.peek(JsonReader.java:363) 7 android.util.JsonReader.expect(JsonReader.java:308) 8 android.util.JsonReader.beginObject(JsonReader.java:293) 9 com.airbnb.lottie.parser.LottieCompositionParser.parse(Unknown Source:47) 10 com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSync(Unknown Source:0) 11 com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(Unknown Source:10) 12 com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(Unknown Source:1) 13 com.airbnb.lottie.LottieCompositionFactory.fromAssetSync(Unknown Source:55) 14 com.airbnb.lottie.LottieCompositionFactory$1.call(Unknown Source:4) 15 com.airbnb.lottie.LottieCompositionFactory$1.call(Unknown Source:0) 16 java.util.concurrent.FutureTask.run(FutureTask.java:266) 17 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 18 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 19 java.lang.Thread.run(Thread.java:764)

As of #830, you can now have separate success and failure handles. Failures will now bubble up to there instead of crashing on a background thread. If this is a device specific issue/platform issue with JsonReader, your best best is to use these new APIs to retry or just drop the animation in those cases.

I’m going to close this for now unless there is more than needs to be done on the lottie side. I’ll try and release 2.6.0 soon with these changes.

@fertwo can you attach the animation?