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

- **ID:** `android/layout-constraint-layout-inflation-error`
- **领域:** android
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ConstraintLayout 2.1.4 | active | — | — |
| ConstraintLayout 2.2.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — If the version is incompatible with other libraries or the app module doesn't have the dependency, inflation fails. (70% 失败率)
- **** — This changes the layout behavior and may break UI design, but doesn't fix the underlying dependency issue. (50% 失败率)
- **** — If the dependency is missing, rebuilding won't fix the classpath issue. (85% 失败率)
