Leon Boon
Leon Boon

Reputation: 357

Lottie animation strange error on Android, works on iOS. The Path cannot loop back on itself

Someone made this Lottie animation for me: https://lottiefiles.com/share/DO3Kpo

It seems to work perfectly on iOS, but on Android it throws the following Exception. We tried a lot but we can't figure out what the problem could be. Anyone any thoughts about it?

Java.Lang.IllegalStateException: Unable to parse composition ---> Java.Lang.IllegalArgumentException: The Path cannot loop back on itself.
  at java.lang.IllegalArgumentException: The Path cannot loop back on itself.
  at at android.view.animation.PathInterpolator.initPath(PathInterpolator.java:185)
  at at android.view.animation.PathInterpolator.initCubic(PathInterpolator.java:158)
  at at android.view.animation.PathInterpolator.<init>(PathInterpolator.java:89)
  at at android.support.v4.view.animation.PathInterpolatorCompat.create(PathInterpolatorCompat.java:82)
  at at com.airbnb.lottie.parser.KeyframeParser.parseKeyframe(KeyframeParser.java:130)
  at at com.airbnb.lottie.parser.KeyframeParser.parse(KeyframeParser.java:58)
  at at com.airbnb.lottie.parser.PathKeyframeParser.parse(PathKeyframeParser.java:21)
  at at com.airbnb.lottie.parser.AnimatablePathValueParser.parse(AnimatablePathValueParser.java:29)
  at at com.airbnb.lottie.parser.AnimatablePathValueParser.parseSplitPath(AnimatablePathValueParser.java:55)
  at at com.airbnb.lottie.parser.AnimatableTransformParser.parse(AnimatableTransformParser.java:54)
  at at com.airbnb.lottie.parser.LayerParser.parse(LayerParser.java:99)
  at at com.airbnb.lottie.parser.LottieCompositionParser.parseAssets(LottieCompositionParser.java:147)
  at at com.airbnb.lottie.parser.LottieCompositionParser.parse(LottieCompositionParser.java:77)
  at at com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSyncInternal(LottieCompositionFactory.java:248)
  at at com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSync(LottieCompositionFactory.java:242)
  at at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:177)
  at at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:171)
  at at com.airbnb.lottie.LottieCompositionFactory.fromAssetSync(LottieCompositionFactory.java:114)
  at at com.airbnb.lottie.LottieCompositionFactory$2.call(LottieCompositionFactory.java:95)
  at at com.airbnb.lottie.LottieCompositionFactory$2.call(LottieCompositionFactory.java:93)
  at at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  at at java.lang.Thread.run(Thread.java:764)

Upvotes: 1

Views: 4543

Answers (3)

Sergio Carvalho
Sergio Carvalho

Reputation: 251

We had a similar issue. We noticed that the crash was thrown by the default failure listener (DEFAULT_FAILURE_LISTENER) in the LottieAnimationView. To avoid the crash we set our own failure listener in our child view:

class CustomLottieAnimatedView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : LottieAnimationView(context, attrs), AnimatedViewsUtils.GBAnimatedView {

    init {
        setFailureListener { throwable ->
            //Setting the failure listener is important to avoid the default implementation to throw an exception and crash
            Log.e(TAG, "Lottie failed to load", throwable)
        }
    }
}

There is no need to extend the LottieAnimationView but it was useful for us to have this implementation so no need to add an empty failure listener in other app screens. Note that this doesn't fix the animation display but in our context, it was acceptable to just avoid the crash and having no animation in such case.

Upvotes: 0

Leon Boon
Leon Boon

Reputation: 357

After debugging i figured out the problem. There where two layers with the same name, they caused a conflict. Not sure if this is a bug in Lottie for Android, the initial version is working perfectly in iOS. So make sure every layer has a different name ;-)

Upvotes: 0

guipivoto
guipivoto

Reputation: 18677

I think you can open an issue at https://github.com/airbnb/lottie-android/issues

Share the link to the json and they may investigate the issue.

I could reproduce it here. It is happening on Android only because the Exception is happening in a Android class:

// Note the class path: android.view.animation.PathInterpolator
at at android.view.animation.PathInterpolator.initPath(PathInterpolator.java:185)
at at android.view.animation.PathInterpolator.initCubic(PathInterpolator.java:158)
at at android.view.animation.PathInterpolator.<init>(PathInterpolator.java:89)
at at android.support.v4.view.animation.PathInterpolatorCompat.create(PathInterpolatorCompat.java:82)
at at com.airbnb.lottie.parser.KeyframeParser.parseKeyframe(KeyframeParser.java:130)

Checking the source code of PathInterpolator:

float fraction = pointComponents[componentIndex++];
float x = pointComponents[componentIndex++];
float y = pointComponents[componentIndex++];
if (fraction == prevFraction && x != prevX) {
    throw new IllegalArgumentException(
            "The Path cannot have discontinuity in the X axis.");
}
if (x < prevX) {
    // Exception is being triggered here due to x < prevX
    throw new IllegalArgumentException("The Path cannot loop back on itself.");
}

PathInterpolator is being invoked by the Lottie library. So, they may provide a better feedback on this issue.

Try there: https://github.com/airbnb/lottie-android/issues

Note that they need the AEP file. So, talk to your friend in order to get that file:

Zip your After Effects AEP file and attach it. Your issue will be auto-closed if it doesn't have an AEP or no explicit reason otherwise is given.

Upvotes: 1

Related Questions