前端之家收集整理的这篇文章主要介绍了
sqlite3在android 操作返回readonly错误,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
502_0@近期使用
sqlite3源
代码编译了一个
sqlite3的库跑在安卓平台上,但发现部分安卓机器会操作失败,返回readonly。经过核查所有需要设定的权限全部都有,经过长时间的排查,终于发现只有在anroid5.0的系统上才会出现。所以定位为系统兼容问题,又经过大量调试发现原因所在:在
sqlite3源
代码中引用到了一种系统库的数据类型 ino_t ,该数据类型在android5.0上的定义有问题,它在5.0下的定义是如果内核是32位则定义为32bit,如果是64位则定义64bit。而
sqlite3所需要的是不关心内核的统一的64bit。所以在32bit的内核机器上如果装有android5.0则导致
sqlite数据被截断而出错。具体修复方式如下:
@H_
502_0@
修改sqlite3.c
代码
@H_
502_0@源
代码:
- ino_t ino; /* Inode number */
修改后:
- #ifdef ANDROID
- // Bionic's struct stat has a 64 bit st_ino on both 32 and 64 bit architectures.
- // ino_t remains 32 bits wide on 32 bit architectures and can lead to inode truncation.
-
- unsigned long long ino; /* Inode number */
-
- #else
-
- ino_t ino; /* Inode number */
-
- #endif
攻城狮一定要坚持才能攻破bug!!!