material-components/material-components-android · error · IllegalArgumentException

A MaterialSpring style must have stiffness value.

Error message

A MaterialSpring style must have stiffness value.

What it means

MotionUtils.resolveAsSpringForce(Callback) reads a spring style (attr MaterialSpring) via obtainStyledAttributes and requires both stiffness and damping. The default value sent to TypedArray.getFloat is Float.MIN_VALUE, so if the resolved style did not define stiffness, the sentinel is returned and the method throws IllegalArgumentException. This exists because SpringForce cannot be meaningfully constructed without a stiffness (and damping) value.

Source

Thrown at lib/java/com/google/android/material/motion/MotionUtils.java:70

   * resolved Material spring attribute
   */
  @NonNull
  public static SpringForce resolveThemeSpringForce(
      @NonNull Context context, @AttrRes int attrResId, @StyleRes int defStyleRes) {

    TypedValue tv = MaterialAttributes.resolve(context, attrResId);
    TypedArray a;
    if (tv == null) {
      a = context.obtainStyledAttributes(null, R.styleable.MaterialSpring, 0, defStyleRes);
    } else {
      a = context.obtainStyledAttributes(tv.resourceId, R.styleable.MaterialSpring);
    }

    SpringForce springForce = new SpringForce();
    try {
      float stiffness = a.getFloat(R.styleable.MaterialSpring_stiffness, Float.MIN_VALUE);
      if (stiffness == Float.MIN_VALUE) {
        throw new IllegalArgumentException("A MaterialSpring style must have stiffness value.");
      }
      float damping = a.getFloat(R.styleable.MaterialSpring_damping, Float.MIN_VALUE);
      if (damping == Float.MIN_VALUE) {
        throw new IllegalArgumentException("A MaterialSpring style must have a damping value.");
      }

      springForce.setStiffness(stiffness);
      springForce.setDampingRatio(damping);
    } finally {
      a.recycle();
    }
    return springForce;
  }

  /**
   * Resolve a duration from a material duration theme attribute.
   *
   * @param context the context from where the theme attribute will be resolved.

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Add <item name="stiffness">[value]</item> to the style referenced by the spring attribute
  2. Verify the style parent is a valid Material spring style (e.g. Widget.Material.Motion.Base to copy defaults)
  3. Confirm the attribute resolves to an @style resource and not a malformed reference
  4. Check the resolve fallback: if tv == null, the defStyleAttr/defStyleRes chain must still supply stiffness

Example fix

<!-- before -->
<style name="MySpring" parent="Widget.Material.Components.Spring">
  <item name="damping">0.8</item>
</style>
<!-- after -->
<style name="MySpring" parent="Widget.Material.Components.Spring">
  <item name="stiffness">300</item>
  <item name="damping">0.8</item>
</style>
Defensive patterns

Strategy: validation

Validate before calling

// Debug-build guard before resolving a spring style
fun Context.hasSpringStiffness(attrResId: Int): Boolean {
    val tv = TypedValue()
    if (theme.resolveAttribute(attrResId, tv, true) && tv.resourceId != 0) {
        val a = obtainStyledAttributes(tv.resourceId, intArrayOf(android.R.attr.stiffness))
        val has = a.hasValue(0)
        a.recycle()
        return has
    }
    return false
}

Try / catch

catch (e: IllegalArgumentException) { Log.e(TAG, "Spring style missing stiffness; fix style resource", e); fallbackToDefaultSpring() }

Prevention

When it happens

Trigger: Calling MotionUtils.resolveAsSpringForce (directly or indirectly, e.g. via MotionUtils or a component resolving ?attr/materialSpring style attributes) with a style resource that lacks the MaterialSpring_stiffness item; also triggered when the TypedValue resolved from attrResId points to a resource that is not actually a MaterialSpring style, so no stiffness is found.

Common situations: App defines a custom spring style overriding the material theme attribute but forgets <item name="stiffness">; typo in styleable item name; using an @style that only sets damping; version changes where Material item names were renamed.

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/11f553baf6bf28b1. Report an issue: GitHub.