jeasonlzy / okhttp-OkGo

OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Apache License 2.0
10.59k stars 2.55k forks source link

Android 9.0上首次打开初始化报错 #795

Open ywp0919 opened 5 years ago

ywp0919 commented 5 years ago

你好,我在正常使用时没有问题,但是最近一个需求是需要把data/data/ 这个默认路径下的okgo.db文件迁移到sd卡的路径上保存,之后的DBHelper类里面的DB_CACHE_NAME也是设置的sd卡上的一个路径,在设置这一切之前会先获取读写的动态权限,获取成功之后才会做这些事情,否则用原来默认的。 但是在Android Studio 上的android 9.0(经初步测试后只发现9.0有这个问题)的模拟器上首次安装运行,获取了读写权限后修改这个存储okgo.db文件的路径后再进行initOkGo的操作就会报错,但是关掉APP重新第二次打开是正常设置成功的(同样是有读写权限的)。 在stackoverflow上找到一个相同的问题:https://stackoverflow.com/questions/51930153/unable-to-open-database-in-android-pie-android-9 不知道大佬们有没有碰到这方面的问题? 报错信息如下(包名信息等用XXX代替了,进行这一步操作的时候我是确定有获取了权限的):

2018-10-29 18:12:30.831 13137-13338/xxx.xxx.xxx E/SQLiteLog: (14) os_unix.c:36667: (13) open(/storage/emulated/0/XXX/db/okgo.db) - 2018-10-29 18:12:30.840 13137-13338/xxx.xxx.xxx E/SQLiteDatabase: Failed to open database '/storage/emulated/0/SafeHome/db/okgo.db'. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:211) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195) at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:503) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:204) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:196) at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880) at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:865) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:739) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:729) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:355) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298) at com.lzy.okgo.db.BaseDao.openWriter(BaseDao.java:58) at com.lzy.okgo.db.BaseDao.(BaseDao.java:50) at com.lzy.okgo.db.CookieManager.(CookieManager.java:50) at com.lzy.okgo.db.CookieManager.getInstance(CookieManager.java:42) at com.lzy.okgo.cookie.store.DBCookieStore.(DBCookieStore.java:54) at xxx.xxx.xxx.http.OkHttp3Utils.getOkHttpClient4OkGo(OkHttp3Utils.java:104) at xxx.xxx.xxx.http.okgo.OkGoUtils.initOkGo(OkGoUtils.java:51) at xxx.xxx.xxx.mvp.activity.view.MainActivity$initOkGo$1.invoke(MainActivity.kt:540) at xxx.xxx.xxx.mvp.activity.view.MainActivity$initOkGo$1.invoke(MainActivity.kt:81) at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Async.kt:140) at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Unknown Source:0) at org.jetbrains.anko.AsyncKt$sam$Callable$761a5578.call(Unknown Source:2) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764)

ywp0919 commented 5 years ago

/storage/emulated/0/XXX/db/okgo.db 这个文件是存在的,那些-wal,-shm,-journal 文件也都有复制过去,就是9.0的模拟器在第一次进入APP给了权限之后初始化会失败,第二次再进app初始化又是正常的了。

gaojiecai commented 5 years ago

这个问题解决了么

ywp0919 commented 5 years ago

没有