android runtime_error ai_generated true

android.view.InflateException: Binary XML file line #XX: Error inflating class androidx.constraintlayout.widget.ConstraintLayout

ID: android/layout-constraint-layout-inflation-error

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
ConstraintLayout 2.1.4 active — — —
ConstraintLayout 2.2.0 active — — —

Root Cause

The ConstraintLayout dependency is missing, version mismatch, or the XML layout contains invalid attributes that prevent inflation.

generic

中文

缺少 ConstraintLayout 依赖项、版本不匹配或 XML 布局包含阻止膨胀的无效属性。

Official Documentation

https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout

Workarounds

  1. 90% success Ensure the ConstraintLayout dependency is in build.gradle (Module: app). Example: implementation 'androidx.constraintlayout:constraintlayout:2.1.4' and sync the project.
    Ensure the ConstraintLayout dependency is in build.gradle (Module: app). Example: implementation 'androidx.constraintlayout:constraintlayout:2.1.4' and sync the project.
  2. 80% success Check for version conflicts by running ./gradlew :app:dependencies and ensure no duplicate or incompatible versions of ConstraintLayout are present.
    Check for version conflicts by running ./gradlew :app:dependencies and ensure no duplicate or incompatible versions of ConstraintLayout are present.
  3. 75% success If using a library module, use 'api' instead of 'implementation' to propagate the dependency to the app module.
    If using a library module, use 'api' instead of 'implementation' to propagate the dependency to the app module.

中文步骤

  1. 确保 build.gradle(模块:app)中有 ConstraintLayout 依赖项。示例:implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 并同步项目。
  2. 运行 ./gradlew :app:dependencies 检查版本冲突,确保没有重复或不兼容的 ConstraintLayout 版本。
  3. 如果使用库模块,使用 'api' 而不是 'implementation' 将依赖项传播到应用程序模块。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    If the version is incompatible with other libraries or the app module doesn't have the dependency, inflation fails.

  2. 50% fail

    This changes the layout behavior and may break UI design, but doesn't fix the underlying dependency issue.

  3. 85% fail

    If the dependency is missing, rebuilding won't fix the classpath issue.