-
Notifications
You must be signed in to change notification settings - Fork 78
SQLiteCantOpenDatabaseException - Android 10 #276
Comments
I tried digging for more useful info, but was not very successful. I grabbed a more succinct stacktrace: Two lines that stood out, just before all the
I'm not sure why it is failing with file operations (double-checked storage permissions were given). I couldn't find |
@denzilferreira This issue could be directly related to the contacts plugin. I filed issue #275. Has there been any progress made with either of these issues? |
I have figured out the problem I was facing. The solution was simple in the end, but not documented. You need to add this file <?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="standalone" type="bool" format="boolean">true</item>
</resources> Whilst I am happy with own implementation, some changes need to be made before I would consider this resolved as the default behaviour crashes on Android 10 devices. It would be great to:
I was reading the source (following the stacktraces I provided) and centred on the following method: /* com.aware.utils.DatabaseHelper.java */
private synchronized SQLiteDatabase getDatabaseFile() {
try {
File aware_folder;
if (mContext.getResources().getBoolean(R.bool.internalstorage)) {
// Internal storage. This is not acceassible to any other apps and is removed once
// app is uninstalled. Plugins can't use it. Hard-coded to off, only change if
// you know what you are doing. Beware!
aware_folder = mContext.getFilesDir();
} else if (!mContext.getResources().getBoolean(R.bool.standalone)) {
// sdcard/AWARE/ (shareable, does not delete when uninstalling)
aware_folder = new File(Environment.getExternalStoragePublicDirectory("AWARE").toString());
} else {
if (isEmulator()) {
aware_folder = mContext.getFilesDir();
} else {
// sdcard/Android/<app_package_name>/AWARE/ (not shareable, deletes when uninstalling package)
aware_folder = new File(ContextCompat.getExternalFilesDirs(mContext, null)[0] + "/AWARE");
}
}
if (!aware_folder.exists()) {
aware_folder.mkdirs();
}
database = SQLiteDatabase.openOrCreateDatabase(new File(aware_folder, this.databaseName).getPath(), this.cursorFactory);
return database;
} catch (SQLiteException e) {
return null;
}
} It makes reference to where files/folders are to be stored/read. I checked my Android 9 devices' filesystem and found the AWARE folder in I have not extensively tested on a matrix of various devices and Android versions, but doing this fixes the problem I was facing. It is possible it has something to do with Privacy changes in Android 10 |
Thanks @ChristopherBull ! I was running into this issue as well, and adding the file you mentioned resolved the errors I was getting related to being unable to open the SQLite db. I ran into this issue while running the android simulator targeting API 30. |
I am experiencing app crashes on every app startup (OnePlus 7t Pro & Google Pixel 3a, both Android 10). The app is failing to create (and therefore not load) the AWARE databases. On fresh app installs (uninstall the app and delete the AWARE folder), the app crashes immediately after AWARE requests contacts and storage permissions.
Development context/background:
api "com.github.denzilferreira:aware-client:master-SNAPSHOT"
(though also explicitly tried versions4.0.820
and4.0.821
)onCreate()
:Aware.startAWARE(this)
Reproducing the issue:
Stacktrace
Logcat stacktrace: stack.txt
This is a stacktrace of the OnePlus 7T Pro (Android 10), with a fresh install of my app, and checked that the AWARE folder did not exist before (and still does not after the app crashed).
Relevant error stacktraces start at:
2019-10-21 14:50:28.066
I have copied what I believe to be the pertinent errors from Logcat, to give you somewhere to jump to in the trace file.
Main crash occurs here:
Note: All devices (Android 9 and 10) spew out the first batch of SQLiteCantOpenDatabaseException errors during the first app load after a fresh install, but presumably the applications that launch successfully (Android 9) are able to eventually create the AWARE DBs.
The text was updated successfully, but these errors were encountered: