airbnb/lottie-android · error · IllegalArgumentException
lottie_rawRes and lottie_fileName cannot be used at the same
Error message
lottie_rawRes and lottie_fileName cannot be used at the same time. Please use only one at once.
What it means
Thrown during LottieAnimationView.init when the XML layout declares BOTH app:lottie_rawRes AND app:lottie_fileName at the same time. The view can only resolve its animation source from one location, so it refuses ambiguous configuration rather than guessing precedence.
Source
Thrown at lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java:165
public LottieAnimationView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, R.attr.lottieAnimationViewStyle);
}
public LottieAnimationView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs, defStyleAttr);
}
private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, defStyleAttr, 0);
cacheComposition = ta.getBoolean(R.styleable.LottieAnimationView_lottie_cacheComposition, true);
boolean hasRawRes = ta.hasValue(R.styleable.LottieAnimationView_lottie_rawRes);
boolean hasFileName = ta.hasValue(R.styleable.LottieAnimationView_lottie_fileName);
boolean hasUrl = ta.hasValue(R.styleable.LottieAnimationView_lottie_url);
if (hasRawRes && hasFileName) {
throw new IllegalArgumentException("lottie_rawRes and lottie_fileName cannot be used at " +
"the same time. Please use only one at once.");
} else if (hasRawRes) {
int rawResId = ta.getResourceId(R.styleable.LottieAnimationView_lottie_rawRes, 0);
if (rawResId != 0) {
setAnimation(rawResId);
}
} else if (hasFileName) {
String fileName = ta.getString(R.styleable.LottieAnimationView_lottie_fileName);
if (fileName != null) {
setAnimation(fileName);
}
} else if (hasUrl) {
String url = ta.getString(R.styleable.LottieAnimationView_lottie_url);
if (url != null) {
setAnimationFromUrl(url);
}
}
View on GitHub (pinned to 05ea92e903)
Solutions
- Open the layout XML and delete either app:lottie_rawRes or app:lottie_fileName so exactly one source attribute remains.
- If you need runtime switching, remove both XML attributes and call setAnimation(rawRes) / setAnimation(fileName) from code instead.
Example fix
<!-- before -->
<com.airbnb.lottie.LottieAnimationView
app:lottie_rawRes="@raw/loading"
app:lottie_fileName="loading.json" />
<!-- after -->
<com.airbnb.lottie.LottieAnimationView
app:lottie_rawRes="@raw/loading" /> Defensive patterns
Strategy: validation
Validate before calling
// Lint/regex check in CI: fail if any layout declares both source attributes // Example shell check (run in CI): // grep -rn 'lottie_rawRes' res/ | while read line; do ... check same element also has lottie_fileName ...
Prevention
- Standardize on one source attribute per project (e.g. always lottie_rawRes).
- Add a CI grep that fails when both app:lottie_rawRes and app:lottie_fileName appear on the same element.
- Prefer setting the animation from code to avoid XML attribute conflicts entirely.
When it happens
Trigger: A layout file containing both android attributes app:lottie_rawRes="@raw/anim" and app:lottie_fileName="anim.json" on the same <com.airbnb.lottie.LottieAnimationView> element, inflated by any LayoutInflater.
Common situations: Copy-pasting a working LottieAnimationView block and forgetting to delete the old source attribute; switching from an assets file to a raw resource (or vice versa) mid-refactor and leaving both declarations.
Related errors
- There is already a cache provider!
- cache file must be a directory
- You must set an images folder before loading an image. Set i
- You must provide a static value in the constructor , call se
AI-assisted analysis of airbnb/lottie-android@05ea92e903 (2026-08-14).
Data as JSON: /api/errors/885ead7562edd6b6.
Report an issue: GitHub.