android runtime_error ai_generated true

android.view.InflateException:二进制 XML 文件第 XX 行:膨胀类 androidx.constraintlayout.widget.ConstraintLayout 时出错

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

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

其他格式: JSON · Markdown 中文 · English
85%修复率
85%置信度
1证据数
2023-01-20首次发现

版本兼容性

版本状态引入弃用备注
ConstraintLayout 2.1.4 active — — —
ConstraintLayout 2.2.0 active — — —

根因分析

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

English

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

generic

官方文档

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 70% 失败

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

  2. 50% 失败

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

  3. 85% 失败

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