android - SQLite 数据库在 Android 设备上创建失败,/data/data/<package> 没有 rw 权限

标签 android sqlite

当大约 1% 的新用户尝试启动我们的应用时,我们的数据库创建失败。主要发生在中国,有时在俄罗斯和其他地方。无法在我的任何设备上重现它,但我已经从日志上传中收集了信息。

我注意到一件事:当 db 创建失败时,我们的包目录/data/data/com.lootworks.swords 的文件权限为 --x,即无法读/写。这与我具有 rwx 访问权限的测试设备不同。

包目录中的 --x 是否导致数据库创建失败?这对我来说肯定听起来很糟糕,除非操作系统在 SQLite 尝试访问它时做了一些时髦的事情,比如更改权限。有人以前见过这个吗?

更多信息:

  • 该应用程序使用子类 SQLiteOpenHelper,非常常规(不复制准备好的数据库文件或类似的东西)
  • 对 getWritableDatabase() 的初始调用发生在 Application.onCreate() 期间
  • 该调用在调用我们的 SQLiteOpenHelper.onCreate() 方法之前就失败了

第一次调用 getWritableDatabase() 时出现异常。那应该回调我们的 onCreate 但在此之前它失败了:

Caused by: android.database.sqlite.SQLiteException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1880)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:851)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:885)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:878)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:599)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:234)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:149)
at com.lootworks.swords.db.SwSqlDbOpenHelper.getDb(SourceFile:379)
at com.lootworks.swords.db.SwSqlDbOpenHelper.getOpenHelper(SourceFile:88)
at com.lootworks.swords.db.SwSqlDb.prepareDatabase(SourceFile:66)
at com.lootworks.swords.SwApplication.onCreate(SourceFile:291)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1004)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3372)
at android.app.ActivityThread.access$2200(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1031)
at android.os.Handler.dispatchMessage(Handler.java:130)
at android.os.Looper.loop(SourceFile:351)
at android.app.ActivityThread.main(ActivityThread.java:3818)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:538)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
at dalvik.system.NativeStart.main(Native Method)

我已经检查过的东西:

  • 有些用户是侧载的(一些 CN 文件共享的东西?)但是有安装程序是 com.android.vending (GPlay) 的例子

最佳答案

Is --x on the package directory why the db create fails?

那是我的猜测。您的进程甚至无法查看 databases/ 是否存在,更不用说创建它了。

Some users are sideloaded (some CN file share thing?) but have examples where installer is com.android.vending (GPlay)

请记住,Play 商店存在一定程度的盗版,因此仅仅因为声称由 Google Play 安装的应用并不意味着该设备与 Play 商店兼容。

关于android - SQLite 数据库在 Android 设备上创建失败,/data/data/<package> 没有 rw 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14664471/

相关文章:

ANDROID_HOME 没有设置?

sqlite - SQLite 中的所有运算符替代项

python - 在 python sqlite3 中使用保存点

python - 在关系数据库中存储不同类型的问题和答案

android - R.Java 总是消失?

Android:如果 ImageView 按矩阵缩放,如何检测 ImageView 上的触摸位置?

android - 在 Android 中生成任意蜂鸣声

点击 webView 输入字段时,Android 软键盘消失

iphone - 如何查看在iphone应用程序中运行的sqlite文件中的数据?

android - 在文件资源管理器 (DDMS) 中找不到 db 文件