feat: 板箱过磅 v3
This commit is contained in:
73
CLAUDE.md
73
CLAUDE.md
@@ -490,12 +490,73 @@ object Key {
|
||||
}
|
||||
```
|
||||
|
||||
### 10. 资源引用错误(最常见的编译失败原因)
|
||||
|
||||
```xml
|
||||
<!-- ❌ 错误: 引用不存在的资源会导致资源合并失败 -->
|
||||
<TextView
|
||||
android:background="@drawable/bg_custom"
|
||||
android:textColor="@color/custom_color"
|
||||
android:text="@string/custom_text" />
|
||||
```
|
||||
|
||||
**问题原因**:
|
||||
- 在布局文件中引用了项目中不存在的 `drawable`、`color`、`string` 等资源
|
||||
- 导致构建时资源合并失败,无法生成R文件
|
||||
- 报错信息: `Resource compilation failed` 或 `AAPT: error: resource ... not found`
|
||||
|
||||
**正确做法**:
|
||||
|
||||
1. **使用已存在的资源** - 先检查资源是否存在
|
||||
```bash
|
||||
# 查找drawable资源
|
||||
find module_base/src/main/res/drawable -name "bg_custom*"
|
||||
|
||||
# 查找color定义
|
||||
grep "custom_color" module_base/src/main/res/values/colors.xml
|
||||
|
||||
# 查找string定义
|
||||
grep "custom_text" module_base/src/main/res/values/strings.xml
|
||||
```
|
||||
|
||||
2. **主动创建缺失的资源** - 如果不存在则创建
|
||||
|
||||
```xml
|
||||
<!-- 创建 drawable: module_base/src/main/res/drawable/bg_custom.xml -->
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/white"/>
|
||||
<corners android:radius="4dp"/>
|
||||
</shape>
|
||||
|
||||
<!-- 添加 color: module_base/src/main/res/values/colors.xml -->
|
||||
<color name="custom_color">#333333</color>
|
||||
|
||||
<!-- 添加 string: module_base/src/main/res/values/strings.xml -->
|
||||
<string name="custom_text">自定义文本</string>
|
||||
```
|
||||
|
||||
3. **使用项目现有资源** - 避免重复创建
|
||||
|
||||
常用资源列表:
|
||||
- **背景**: `bg_white_radius_8`, `bg_gray_radius_4`, `bg_primary_radius_4`
|
||||
- **颜色**: `white`, `black`, `colorPrimary`, `text_normal`, `text_gray`, `text_red`
|
||||
- **文字**: 优先直接写中文字符串,少用 string 资源
|
||||
|
||||
**检查清单**:
|
||||
- ✅ 创建/修改布局文件前,确保引用的资源都存在
|
||||
- ✅ 新增drawable时,在正确的module下创建(通常是`module_base`)
|
||||
- ✅ 新增color/string时,添加到对应的values文件中
|
||||
- ✅ 使用IDE的自动补全和资源预览功能,避免拼写错误
|
||||
- ✅ 构建失败时,优先检查资源引用问题
|
||||
|
||||
## 错误排查流程
|
||||
|
||||
1. **DataBinding错误** → 检查import包名、枚举值
|
||||
2. **Unresolved reference** → 检查import语句、常量定义
|
||||
3. **suspend function错误** → 在`viewModelScope.launch`中调用
|
||||
4. **仍有问题** → `./gradlew clean` 后重新构建
|
||||
1. **资源引用错误** → 检查drawable/color/string是否存在,主动创建缺失资源
|
||||
2. **DataBinding错误** → 检查import包名、枚举值
|
||||
3. **Unresolved reference** → 检查import语句、常量定义
|
||||
4. **suspend function错误** → 在`viewModelScope.launch`中调用
|
||||
5. **仍有问题** → `./gradlew clean` 后重新构建
|
||||
|
||||
## 快速修复命令
|
||||
|
||||
@@ -512,13 +573,15 @@ grep -A 5 "enum class DataLayoutType" module_base/src --include="*.kt"
|
||||
|
||||
## 开发原则
|
||||
|
||||
- ✅ **资源引用必须存在** - 创建/修改布局前,确保drawable/color/string资源真实存在或主动创建
|
||||
- ✅ 优先使用项目现有基类和封装
|
||||
- ✅ 充分利用PadDataLayout和PadSearchLayout
|
||||
- ✅ 充分利用PadDataLayout和PadSearchLayout组件
|
||||
- ✅ 遵循统一命名规范
|
||||
- ✅ pageType用LiveData不用普通变量
|
||||
- ✅ FlowBus.emit()必须在协程中调用
|
||||
- ✅ 图片上传使用newName字段
|
||||
- ✅ RecyclerView手动更新adapter不用items属性
|
||||
- ✅ 新建Activity后必须在AndroidManifest.xml中注册
|
||||
|
||||
## 技术栈
|
||||
|
||||
|
||||
@@ -132,12 +132,12 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_shouyun_dbzl"
|
||||
android:minHeight="150dp"
|
||||
android:padding="20dp">
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvWeight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@{viewModel.totalWeight}"
|
||||
android:textColor="@color/text_red"
|
||||
@@ -152,8 +152,9 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_toEndOf="@id/tvWeight"
|
||||
android:text="kg"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="18sp" />
|
||||
android:textSize="24sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user