koral--/android-gif-drawable · error · IllegalArgumentException

Expected string, drawable, mipmap or raw resource type.

Error message

Expected string, drawable, mipmap or raw resource type. '<resourceTypeName>' is not supported

What it means

GifTextureView resolves the XML attribute referencing a GIF source. When android:src (or the library's gifSource attribute) is set to a resource ID, it checks the resource type name via Resources.getResourceTypeName(). Only 'drawable', 'mipmap' and 'raw' resource types are valid GIF sources; 'string' falls back to treating the value as an asset filename. Any other resource type (e.g. 'array', 'bool', 'id', 'layout') makes the view throw this IllegalArgumentException from findSource, called during init.

Solutions

  1. Move the GIF into res/drawable (or drawable-nodpi), res/raw, or res/mipmap and reference it with @drawable/..., @raw/... or @mipmap/...
  2. If the GIF is an asset instead, keep the attribute as a string literal (e.g. app:gifSource="gifs/anim.gif") pointing at the file inside src/main/assets
  3. Check the attribute value for typos in the resource type prefix — an unrecognized prefix can resolve to the wrong resource type
  4. Verify the resource ID actually belongs to your media resource (print getResources().getResourceTypeName(id) while debugging)

Example fix

<!-- before -->
<pl.droidsonroids.gif.GifTextureView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:gifSource="@array/gif_names" />

<!-- after -->
<pl.droidsonroids.gif.GifTextureView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:gifSource="@raw/animation" />
Defensive patterns

Strategy: validation

Validate before calling

// Kotlin: verify the resource type before assigning to GifTextureView
fun isSupportedGifSource(res: Resources, @AnyRes resId: Int): Boolean {
    val type = res.getResourceTypeName(resId)
    return type in setOf("drawable", "mipmap", "raw", "string")
}
// usage: require(isSupportedGifSource(resources, R.raw.animation))

Prevention

When it happens

Trigger: Setting the GifTextureView source attribute in XML (app:gifSource or android:src with a resource ID) to a resource whose type is not drawable/mipmap/raw/string — for example @array/..., @layout/..., @bool/..., or an ID-type resource passed programmatically via attributes.

Common situations: Developers placing GIF files under the wrong res/ folder (e.g. res/xml or res/raw misspelled), referencing the wrong @ resource by autocomplete accident, or using a data-binding/generated ID that points to a non-media resource type. Most commonly it is a typo in the resource qualifier (@drawble, @rawr) so the resource resolves to an unexpected type.

Related errors


AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10). Data as JSON: /api/errors/ba42995c4b29cdf3. Report an issue: GitHub.

Appendix: source

Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifTextureView.java:149

	 * @param surfaceTexture ignored
	 */
	@Override
	public void setSurfaceTexture(@NonNull SurfaceTexture surfaceTexture) {
		throw new UnsupportedOperationException("Changing SurfaceTexture is not supported");
	}

	private static InputSource findSource(final TypedArray textureViewAttributes) {
		final TypedValue value = new TypedValue();
		if (!textureViewAttributes.getValue(R.styleable.GifTextureView_gifSource, value)) {
			return null;
		}

		if (value.resourceId != 0) {
			final String resourceTypeName = textureViewAttributes.getResources().getResourceTypeName(value.resourceId);
			if (GifViewUtils.SUPPORTED_RESOURCE_TYPE_NAMES.contains(resourceTypeName)) {
				return new InputSource.ResourcesSource(textureViewAttributes.getResources(), value.resourceId);
			} else if (!"string".equals(resourceTypeName)) {
				throw new IllegalArgumentException(
						"Expected string, drawable, mipmap or raw resource type. '" + resourceTypeName
								+ "' is not supported");
			}
		}
		return new InputSource.AssetSource(textureViewAttributes.getResources().getAssets(), value.string.toString());
	}

	private static class RenderThread extends Thread implements SurfaceTextureListener {

		final ConditionVariable isSurfaceValid = new ConditionVariable();
		private GifInfoHandle mGifInfoHandle = new GifInfoHandle();
		private IOException mIOException;
		long[] mSavedState;
		private final WeakReference<GifTextureView> mGifTextureViewReference;

		RenderThread(final GifTextureView gifTextureView) {
			super("GifRenderThread");
			mGifTextureViewReference = new WeakReference<>(gifTextureView);

View on GitHub (pinned to 26ff795f78)