본문 바로가기

IT/안드로이드 관련

[Android] Lottie setImagesFolder Error 해결방법 (You must set an images folder before loading an image. Set it with LottieComposition setImagesFolder or LottieDrawable setImagesFolder)

 안녕하세요 YTS 입니다.


오늘은 Android App에서 Lottie 라이브러리를 사용하다가 나오는 에러인 setImagesFolder 문제의 해결방법을 알아보겠습니다.


에러로그는 밑에와 같이 출력이 될텐데요.


You must set an images folder before loading an image. Set it with LottieComposition setImagesFolder or LottieDrawable setImagesFolder 




우선 첫번째로 에러가 발생한부분의 LottieAnimationView 부분을 찾아보셔야합니다.


<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_fileName="intro.json" />


</androidx.constraintlayout.widget.ConstraintLayout>

<data class="IntroBinding" />

</layout>


딱보니 LottieAnimationView에서 intro.json 파일에 어떤 문제가 있는게 확실하겠네요


animation json 파일이기때문에 엄청나게 많은 내용이 담겨져있을텐데요.

저희가 봐야할 부분은 image파일이 씌여진부분을 찾아내야합니다.


"assets": [
{
"id": "image_0",
"w": 1920,
"h": 1080,
"u": "images/",
"p": "intro_0.png",
"e": 0
},
{
"id": "image_1",
"w": 1920,
"h": 1080,
"u": "images/",
"p": "intro_1.png",
"e": 0
},



 이렇게 assets 배열안에 png파일이 있네요. 정리를 해보면 저 에러는 images/intro_0.png 와 images/intro_1.png 파일을 찾을 수 없기 때문에 발생하는 에러네요


해결방법


 1. 우선 에펙에서 추출한 json파일을 제외하고도 나온 png 파일을 assets 밑에 경로에 맞게 생성하고 파일을 넣습니다.




 2. 에러가 발생한 xml파일로 돌아와 해당 경로를 set합니다. 저는 파일경로를 images/로 해놨기 때문에 lottie_imageAssetsFolder를 images로 세팅합니다.



<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_fileName="intro.json"
app:lottie_imageAssetsFolder="images" />



이상입니다 : ) 오늘도 즐거운 하루되세요!