koral--/android-gif-drawable · error · UnsupportedOperationException
Changing SurfaceTexture is not supported
Error message
Changing SurfaceTexture is not supported
What it means
GifTextureView overrides setSurfaceTexture to forbid replacing the SurfaceTexture it drives GIF decoding with. Any call throws UnsupportedOperationException('Changing SurfaceTexture is not supported'), since the texture lifecycle is owned by the view's rendering pipeline.
Solutions
- Remove the setSurfaceTexture call — let GifTextureView create and manage its own SurfaceTexture.
- If SurfaceTexture reuse is required, use a plain TextureView instead of GifTextureView.
- Interact with the GIF via GifDrawable/handle APIs rather than the texture.
Example fix
// before gifTextureView.setSurfaceTexture(sharedSurfaceTexture); // after // removed: GifTextureView owns its SurfaceTexture; use a plain TextureView if you must share one
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(view instanceof GifTextureView)) { view.setSurfaceTexture(surfaceTexture); } Type guard
boolean supportsSurfaceTextureChange(View v) { return !(v instanceof GifTextureView); } Try / catch
try { view.setSurfaceTexture(surfaceTexture); } catch (UnsupportedOperationException e) { /* GifTextureView owns its SurfaceTexture */ } Prevention
- Let GifTextureView create its own SurfaceTexture
- Use a plain TextureView when SurfaceTexture reuse is required
- Avoid generic view-config code that sets textures on all TextureViews
When it happens
Trigger: Calling gifTextureView.setSurfaceTexture(surfaceTexture) directly, e.g. code that shares or reassigns SurfaceTextures across TextureViews.
Common situations: Reusing an existing SurfaceTexture from another view for performance; generic view-configuration code paths that call setSurfaceTexture on any TextureView.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Changing SurfaceTextureListener is not supported
- Sample size out of range <1, 65535>
- Bitmap is recycled
- Bitmap ia too small, size must be greater than or equal to…
- Only Config.ARGB_8888 is supported. Current bitmap config
AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10).
Data as JSON: /api/errors/dc71e689305d3fce.
Report an issue: GitHub.
Appendix: source
Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifTextureView.java:135
/**
* Always returns null since changing {@link SurfaceTextureListener} is not supported.
*
* @return always null
*/
@Override
public SurfaceTextureListener getSurfaceTextureListener() {
return null;
}
/**
* Always throws {@link UnsupportedOperationException}. Changing {@link SurfaceTexture} is not
* supported.
*
* @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");
}
}View on GitHub (pinned to 26ff795f78)