Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Reader AssertionError when doInBackground (Android 7, 8) #667

Closed
fertwo opened this issue Mar 8, 2018 · 52 comments · Fixed by #1234
Closed

JSON Reader AssertionError when doInBackground (Android 7, 8) #667

fertwo opened this issue Mar 8, 2018 · 52 comments · Fixed by #1234

Comments

@fertwo
Copy link

fertwo commented Mar 8, 2018

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

@gpeal
Copy link
Collaborator

gpeal commented Mar 9, 2018

@fertwo can you attach the animation?

@fertwo
Copy link
Author

fertwo commented Mar 12, 2018

animation.zip

@7heaven
Copy link

7heaven commented Mar 15, 2018

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

@gpeal
Copy link
Collaborator

gpeal commented Mar 15, 2018

@fertwo @7heaven Can either of you attach a sample project that reproduces this? The animation posted above doesn't crash for me.
image

@fertwo why does you animation use images? It looks like they can all be shape layers. Please refer to the images documentation here.

@Frank1234
Copy link

I'm having this on Lottie 2.5.4 and Android 8.0 and 8.1. In my crash logs, I cannot reproduce.

@gpeal
Copy link
Collaborator

gpeal commented May 8, 2018

@Frank1234 you're seeing it in production logs? Can you paste the exact stack?

@Frank1234
Copy link

Yes, in production logs. Here are the details:

Fatal Exception: java.lang.RuntimeException
An error occurred while executing doInBackground()
android.os.AsyncTask$3.done (AsyncTask.java:353)
java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383)
java.util.concurrent.FutureTask.setException (FutureTask.java:252)
java.util.concurrent.FutureTask.run (FutureTask.java:271)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
java.lang.Thread.run (Thread.java:764)
Caused by java.lang.AssertionError
android.util.JsonReader.peek (JsonReader.java:363)
android.util.JsonReader.expect (JsonReader.java:308)
android.util.JsonReader.beginObject (JsonReader.java:293)
arrow_right
com.airbnb.lottie.parser.LottieCompositionParser.parse (LottieCompositionParser.java:42)
com.airbnb.lottie.LottieComposition$Factory.fromJsonSync (LottieComposition.java:276)
com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground (AsyncCompositionLoader.java:22)
com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground (AsyncCompositionLoader.java:12)
android.os.AsyncTask$2.call (AsyncTask.java:333)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
java.lang.Thread.run (Thread.java:764)

Device
Brand: samsung
Model: SM-A520F
Orientation: Portrait
RAM free: 203.76 MB
Disk free: 4.89 GB
plat_android Operating System
Version: 8.0.0
Orientation: Portrait
Rooted: No
bug_report Crash
Date: May 10, 2018, 9:36:00 AM
App version: 4.1.0 (2023180)

@falcon4ever
Copy link

falcon4ever commented May 10, 2018

I'm seeing the same crash bug occur in Crashlytics/Firebase for our app in prod. Unfortunately I've been unable to reproduce the issue so far with any of my test devices.

My stacktrace is similar to the ones posted above:

Devices
-------

# Date: 2018-05-05T05:56:00Z
# OS Version: 8.1.0
# Device: Nexus 6P
# RAM Free: 100%
# Disk Free: 100%

# Date: 2018-05-06T15:21:00Z
# OS Version: 8.0.0
# Device: SM-G955U
# RAM Free: 40.7%
# Disk Free: 49.5%


Stacktrace from Crashlytics:
----------------------------

#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(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)

#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)

@gpeal
Copy link
Collaborator

gpeal commented May 10, 2018

@Frank1234 @falcon4ever Are there any commonalities like specific versions of Android?

@alliecurry
Copy link

alliecurry commented May 11, 2018

Hi, I've been experiencing this same issue... @gpeal seems to be only on 8.0.0 and 8.1.0 devices, in my case (over 25 reports, so far). I have the same stacktrace as falcon4ever, above.

@falcon4ever
Copy link

@gpeal Same like Allie mentioned, I've only seen it happening on devices running 8.0.0 and 8.1.0. In my case it's just a handful of crashes, and we have like 30+% of our users running Android 8.x or newer.

So it's possible it only affects certain devices/firmwares?

@gpeal
Copy link
Collaborator

gpeal commented May 13, 2018

@alliecurry @falcon4ever Any other patterns you can deduce from your crash logs? Samsung, etc?

@falcon4ever
Copy link

@gpeal I don't see any particular thing that stands out, just those devices above.

btw, I also noticed v2.5.5 got release 3 days ago without a change log updates. Is that version including important changes?

@alliecurry
Copy link

Seems to affect a multitude of devices:
screen shot 2018-05-15 at 11 48 17 am

@awenger
Copy link

awenger commented May 17, 2018

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

@Frank1234
Copy link

I've added our details and log to the JsonReader issue report.

@gpeal
Copy link
Collaborator

gpeal commented Jul 16, 2018

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.

@gpeal gpeal closed this as completed Jul 16, 2018
@BUPT-LXP
Copy link

I got the same problem on 7.X and 8.X with Lottie 2.5.1. So sad that Google said that they will not fix this because no one can reproduce this bug steadily.

@TobiasReich
Copy link

TobiasReich commented Aug 1, 2018

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?!

@andyxialm
Copy link

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)

@awenger
Copy link

awenger commented Oct 24, 2018

@TobiasReich , I think there is no way that this can be circumvented by just catching the exception. The json is parsed for a reason, something depends on the data being parsed. If the exception is thrown you don't have the data, so you can't proceed.
In general the next steps are what was already mentioned in the ticket:

... If you are still facing this problem, please open new issue and add the relevant information along with reference to earlier issue.

@NewOrin
Copy link

NewOrin commented Jan 9, 2019

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)

兄弟你解决这个问题了吗?

@rasoulmiri
Copy link

i have issue to

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.LottieCompositionFactory.fromJsonReaderSync(SourceFile:229)
at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(SourceFile:163)
at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(SourceFile:157)
at com.airbnb.lottie.LottieCompositionFactory.fromAssetSync(SourceFile:100)
at com.airbnb.lottie.LottieCompositionFactory$1.call(SourceFile:81)
at com.airbnb.lottie.LottieCompositionFactory$1.call(SourceFile:79)
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)

@TobiasReich
Copy link

So could we please get an exception wrapping around that? I still hope this might be possible.

@gpeal
Copy link
Collaborator

gpeal commented Jan 13, 2019

@rasoulmiri Please attach your animation.

@B100402352
Copy link

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)

@B100402352
Copy link

May be it's because "context.getResources().openRawResource" cannot work correctly in background thread when starting?

@gpeal
Copy link
Collaborator

gpeal commented Feb 21, 2019

It's not clear to my why/how this could happen inconsistently and I've never been able to repro it. I'll take a look at it but if anybody has some time to investigate, that would be great.

@nico-gonzalez
Copy link

@gpeal having the same problem using lottie 2.7.0, but as many said I cannot reproduce it. Crashlytics reports shows that is happening in a variety of manufacturers and android 7.1.2 and 8.x. Unfortunately, I don't have time to investigate this. Let me know if I can provide any useful info

@senlinxuefeng
Copy link

i met the same problem using lottie 2.5.1,on 魅族M5 Note
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
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(Proguard:42)
at com.airbnb.lottie.LottieComposition$Factory.fromJsonSync(Proguard:276)
at com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground(Proguard:22)
at com.airbnb.lottie.parser.AsyncCompositionLoader.doInBackground(Proguard:12)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 3 more

@mardann
Copy link

mardann commented Apr 15, 2019

We are having a similar problem. Crashlytics is reporting several tens of crashes (amung an audience of 300K). Haven't been able to reproduce.

Lottie v. 2.7.0

Crash demogarphics:
image

Lottie file:
wave_bottom_padding.json.zip

Stacktrace:

# URL: -------
# Organization: -------
# Platform: android
# Application: PROD
# Version: -------
# Bundle Identifier: ------
# Issue ID: -------
# Session ID: --------
# Date: 2019-04-15T07:52:00Z
# OS Version: 8.1.0
# Device: Redmi Note 5
# RAM Free: 48.9%
# Disk Free: 78.4%


#0. Crashed: main
      at com.airbnb.lottie.LottieAnimationView$2.onResult(LottieAnimationView.java:68)
      at com.airbnb.lottie.LottieAnimationView$2.onResult(LottieAnimationView.java:66)
      at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:167)
      at com.airbnb.lottie.LottieTask.access$000(LottieTask.java:26)
      at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:142)
      at android.os.Handler.handleCallback(Handler.java:794)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:176)
      at android.app.ActivityThread.main(ActivityThread.java:6635)
      at java.lang.reflect.Method.invoke(Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

--

Fatal Exception: java.lang.IllegalStateException: Unable to parse composition
      at com.airbnb.lottie.LottieAnimationView$2.onResult(LottieAnimationView.java:68)
      at com.airbnb.lottie.LottieAnimationView$2.onResult(LottieAnimationView.java:66)
      at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:167)
      at com.airbnb.lottie.LottieTask.access$000(LottieTask.java:26)
      at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:142)
      at android.os.Handler.handleCallback(Handler.java:794)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:176)
      at android.app.ActivityThread.main(ActivityThread.java:6635)
      at java.lang.reflect.Method.invoke(Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

Caused by java.util.concurrent.ExecutionException: java.lang.AssertionError
      at java.util.concurrent.FutureTask.report(FutureTask.java:123)
      at java.util.concurrent.FutureTask.get(FutureTask.java:193)
      at com.airbnb.lottie.LottieTask$2.run(LottieTask.java:189)

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.LottieCompositionFactory.fromJsonReaderSync(LottieCompositionFactory.java:229)
      at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:163)
      at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:157)
      at com.airbnb.lottie.LottieCompositionFactory.fromRawResSync(LottieCompositionFactory.java:129)
      at com.airbnb.lottie.LottieCompositionFactory$2.call(LottieCompositionFactory.java:116)
      at com.airbnb.lottie.LottieCompositionFactory$2.call(LottieCompositionFactory.java:114)
      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)
...

lottie_crash_stacktrace.txt

@slimshader
Copy link

Just encountered this too after updating animation. It worked with first one but fails with new one, main difference is the size 8kb (is ok) vs 17kb (exception)

@roadroot
Copy link

I know that this is a weird question but have you putted the json in assets folder and set the build action to androidasset? I had the same error and fixed it by setting the build action to androidasset.
Thnx

gpeal added a commit that referenced this issue May 30, 2019
There's a dependency on OKIO & 8 classes copied from Moshi. Need to figure out best path forward. Ideally we don't depend on all of Moshi but still get the gains of the new JsonReader & Options api. This should fix the random Android 8 crashes.

Performance
I ran the snapshot tests with ~1800 animations and summed up just the parsing time. The old parsing code took 13,145ms and 13,645ms on each test run (avg 13,395ms). The new code took 12,858ms each time. There aren't enough trials to deduce statistical differences but if these numbers hold, the new code parses ~5% faster.
It does reduce memory allocations during parsing which may contribute to the performance improvement.

I'm leaning on merging this to hopefully fix #667
@AndroidDeveloperLB
Copy link

On which version of Lottie was this fixed?

I had this on 3.0.3 , in this form:

2019-06-19_10-49-04.zip

Sadly I can't update to 3.0.6 or even 3.0.4 , because it doesn't support this:
#1270

@LeoJHarris
Copy link

@mohamed-azikiou that resolved my issue as well, moved json file to assets folder, set build action to androidasset - issue resolved.

@gpeal
Copy link
Collaborator

gpeal commented Jun 22, 2019

@AndroidDeveloperLB The JsonReader change that you're encountering is the fix for this bug.

@AndroidDeveloperLB
Copy link

@gpeal I see. Are there any other known crashes on latest versions of the library though?

@gpeal
Copy link
Collaborator

gpeal commented Jun 23, 2019

@AndroidDeveloperLB No known crashes in 3.0.7

@AndroidDeveloperLB
Copy link

@gpeal I see. Thank you. I hope a new version will come out soon.

@Cdik
Copy link

Cdik commented Jun 25, 2019

Also pops up with com.github.wwdablu:lottiebottomnav:1.0.0
I'm using lottie:3.0.7
I had to set dataBinding { enabled = true } otherwise it rises another error regarding Landroidx/databinding/DataBinderMapperImpl;

Also reported on github.wwdablu

@Cdik
Copy link

Cdik commented Jun 25, 2019

Also pops up with com.github.wwdablu:lottiebottomnav:1.0.0
I'm using lottie:3.0.7
I had to set dataBinding { enabled = true } otherwise it rises another error regarding Landroidx/databinding/DataBinderMapperImpl;

Also reported on github.wwdablu

It works if you put the lottie animation inside the assets folder (it crashes if inside the raw folder)
And dataBinding { enabled = true } needs to be set in the gradle file otherwise you'll end up with Landroidx/databinding/DataBinderMapperImpl; error

If someone is interested in using lottie animations with com.github.wwdablu:lottiebottomnav:1.0.0 don't forget to declare the source to be MenuItem.Source.Assets and not MenuItem.Source.Raw

@Cdik
Copy link

Cdik commented Jul 4, 2019

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

@1wayticket
Copy link

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

Sorry,I want to ask someone else about multi lottie. So my comment is not about you,Sorry for disturb.

@1wayticket
Copy link

I know that this is a weird question but have you putted the json in assets folder and set the build action to androidasset? I had the same error and fixed it by setting the build action to androidasset.
Thnx

I have the same question with you ,So can you share about your solution -- set the build action to androidasset. I'm confused about how to set it? or can you leave your WeChat or Email?

@AndroidDeveloperLB
Copy link

Sadly updating to 3.0.7 causes a different issue:
#1298

Is there a version that doesn't have both of those issues?
Is it true that putting the Lottie files (the json files) into assets folder will fix it?

@Cdik
Copy link

Cdik commented Jul 10, 2019

Sadly updating to 3.0.7 causes a different issue:
#1298

Is there a version that doesn't have both of those issues?
Is it true that putting the Lottie files (the json files) into assets folder will fix it?

@AndroidDeveloperLB, this has fixed mine at least! I guess it doesn't change much to put them in /raw or /assets, you just need to remember setup the correct one in the code. (It might change something in term of performances though but I haven't checked)

@AndroidDeveloperLB
Copy link

@Cdik I had this issue with the most basic usage of Lottie, in 2 animationViews .
In both of them, we have in layout XML file app:lottie_rawRes="@raw/... .

So instead of this, I called in code animationView.setAnimation("...json").

Do you think it's similar to what you did?
Do you use 3.0.3 now, or 3.0.7 ? The 3.0.7 version causes a different serious issue for us, so I need to choose if I want to deal with this issue or the other :(

@AndroidDeveloperLB
Copy link

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

#1298 (comment)

@sujitpanda
Copy link

I am using 3.0.7 version and it crashes for with same error when i do setAnimation() programatically with custom view.
In my custom view and i am getting the json file name from custom view attribute and setting it in setAnimation() like below.

val courseCardAnimJson = typedArray.getString(R.styleable.PickCourseItem_courseCardAnimJson)
courseAnimImage.setAnimation(courseCardAnimJson)

But if i pass the file name directly to the setAnimation() as below it works fine.
courseAnimImage.setAnimation("basic_course.json")

@hiteshsahu
Copy link

For me it happen when I misspelled my Lottie file name. After referring to correct file this error was gone.

image

@Damercy
Copy link

Damercy commented Feb 16, 2021

Same issue occurs if I use setAnimation(R.raw.animation). 😏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.