{"record":{"id":"885ead7562edd6b6","repo":"airbnb/lottie-android","slug":"lottie-rawres-and-lottie-filename-cannot-be-used-a","errorCode":null,"errorMessage":"lottie_rawRes and lottie_fileName cannot be used at the same time. Please use only one at once.","messagePattern":"lottie_rawRes and lottie_fileName cannot be used at the same time\\. Please use only one at once\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java","lineNumber":165,"sourceCode":"\n  public LottieAnimationView(Context context, AttributeSet attrs) {\n    super(context, attrs);\n    init(attrs, R.attr.lottieAnimationViewStyle);\n  }\n\n  public LottieAnimationView(Context context, AttributeSet attrs, int defStyleAttr) {\n    super(context, attrs, defStyleAttr);\n    init(attrs, defStyleAttr);\n  }\n\n  private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {\n    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, defStyleAttr, 0);\n    cacheComposition = ta.getBoolean(R.styleable.LottieAnimationView_lottie_cacheComposition, true);\n    boolean hasRawRes = ta.hasValue(R.styleable.LottieAnimationView_lottie_rawRes);\n    boolean hasFileName = ta.hasValue(R.styleable.LottieAnimationView_lottie_fileName);\n    boolean hasUrl = ta.hasValue(R.styleable.LottieAnimationView_lottie_url);\n    if (hasRawRes && hasFileName) {\n      throw new IllegalArgumentException(\"lottie_rawRes and lottie_fileName cannot be used at \" +\n          \"the same time. Please use only one at once.\");\n    } else if (hasRawRes) {\n      int rawResId = ta.getResourceId(R.styleable.LottieAnimationView_lottie_rawRes, 0);\n      if (rawResId != 0) {\n        setAnimation(rawResId);\n      }\n    } else if (hasFileName) {\n      String fileName = ta.getString(R.styleable.LottieAnimationView_lottie_fileName);\n      if (fileName != null) {\n        setAnimation(fileName);\n      }\n    } else if (hasUrl) {\n      String url = ta.getString(R.styleable.LottieAnimationView_lottie_url);\n      if (url != null) {\n        setAnimationFromUrl(url);\n      }\n    }\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/airbnb/lottie-android/blob/05ea92e90381eb8a8ae06855ea2b74f322bebbec/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java#L147-L183","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n<com.airbnb.lottie.LottieAnimationView\n    app:lottie_rawRes=\"@raw/loading\"\n    app:lottie_fileName=\"loading.json\" />\n\n<!-- after -->\n<com.airbnb.lottie.LottieAnimationView\n    app:lottie_rawRes=\"@raw/loading\" />","handlingStrategy":"validation","validationCode":"// Lint/regex check in CI: fail if any layout declares both source attributes\n// Example shell check (run in CI):\n// grep -rn 'lottie_rawRes' res/ | while read line; do ... check same element also has lottie_fileName ...","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["xml","configuration","layout","init"],"backgroundTag":null,"analyzedSha":"05ea92e90381eb8a8ae06855ea2b74f322bebbec","analyzedAt":"2026-08-14T00:51:35.636Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}