复现步骤
删除项目中原有的objectbox-moduls文件夹,重新编译项目之后,打包运行APP,报了如下错误
io.objectbox.exception.DbException:
Incoming entity ID 3:1254311430231230573 does not match existing UID 7915716400036480317
产生原因分析
由于我们修改了有@Entity标注的实体的内容,重新编译项目之后,生成的UID和APP本地缓存里面的Incoming Entity ID不一致。
解决步骤
查找官方文档,按下面步骤操作就能解决。
- Delete the JSON file (objectbox-models/default.json)(删除objectbox-models/default.json)
- Build the project to generate a new JSON file from scratch(重新build项目,生成一个新的JSON文件)
- Commit the recreated JSON file to your VCS (e.g. git)(提交到本地版本管理)
- Delete all previously create ObjectBox databases (for Android, e.g. delete the app’s data or uninstall the app)(删除之前所有创建的ObjectBox的数据库,在Android中就是删除APP的数据或者直接卸载APP)