SQLite DB 创建在 Android 设备上失败,/data/data/<package> 没有 rw 权限



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

我注意到一件事:当数据库创建失败时,我们的包目录/data/data/com.lootworks.剑的文件权限是--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)的例子

包目录中的--x是数据库创建失败的原因吗?

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

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

请记住,Play商店是盗版的,所以仅仅因为该应用程序声称是由Google Play安装的并不意味着该设备与Play商店兼容。

相关内容

最新更新