Ionic Storage - Open database failed!

So my app is working fine with ionic serve, but on a real Android 7.1.1 device Ionic Storage isn’t working.

In logcat I found (see first and last line, stacktrace in between).
05-13 17:27:50.191 I/chromium(18272): [INFO:CONSOLE(175)] "OPEN database: _ionicstorage", source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (175) 05-13 17:27:50.200 W/System.err(18272): org.json.JSONException: Index 1 out of range [0..1) 05-13 17:27:50.200 W/System.err(18272): at org.json.JSONArray.get(JSONArray.java:293) 05-13 17:27:50.200 W/System.err(18272): at org.json.JSONArray.getJSONArray(JSONArray.java:496) 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin.execInBackgroundAndReturnResults(SQLitePlugin.java:73) 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin.runInBackground(SQLitePlugin.java:66) 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin.access$000(SQLitePlugin.java:24) 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin$1.run(SQLitePlugin.java:56) 05-13 17:27:50.200 W/System.err(18272): at android.os.Handler.handleCallback(Handler.java:751) 05-13 17:27:50.200 W/System.err(18272): at android.os.Handler.dispatchMessage(Handler.java:95) 05-13 17:27:50.200 W/System.err(18272): at android.os.Looper.loop(Looper.java:154) 05-13 17:27:50.200 W/System.err(18272): at android.os.HandlerThread.run(HandlerThread.java:61) 05-13 17:27:50.219 I/chromium(18272): [INFO:CONSOLE(197)] "OPEN database: _ionicstorage FAILED, aborting any pending transactions", source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (197)

However, I have checked that cordova-plugin-sqlite-2 and cordova-sqlite-storage are listed in both package.json and config.xml.

Any ideas?

Bonus fact, I don’t know if it might be related. It had been a long time since my app had been tested on this real device, so when I did ionic run android I got an error.

Error: adb: Command failed with exit code 1 Error output: Failed to install /Users/sune/Code/gadabout/platforms/android/build/outputs/apk/android-debug.apk: Failure [INSTALL_FAILED_VERSION_DOWNGRADE]

Since I have done ionic platform rm android && ionic platform add android not long ago, I just tried uninstalled the app on the device, and then hit ionic run android with success.

Could the old version of the app be hanging on to the database? Or unrelated?

+1 Same problem here…

Hi

found the problem in my case.

I had two sqlite plugins configured in my config.xml

<plugin name="cordova-plugin-sqlite-2" spec="~1.0.4" /> <plugin name="cordova-sqlite-storage" spec="~2.0.3" />

I remove both, rebuilt android platform (remove and then add).

Later I added the sqlite plugin as per doc of Ionic

cordova plugin add cordova-sqlite-storage --save

Now all ok

OPEN database: __mydb SQLitePlugin.js:175 new transaction is waiting for open operation SQLitePlugin.js:106 OPEN database: __mydb - OK SQLitePlugin.js:179 DB opened: __mydb SQLitePlugin.js:80

Hope this helps.

Regards

Tom

3 Likes

If you are using more than one Sqlite plugin, like I was, try removing one of them.

I uninstalled cordova-plugin-sqlite-2, and the problem was gone.
For now I won’t claim this to be the actual solution to the problem, as I haven’t been able to find if there are any differences between the Sqlite plugins, that might cause other problems.

2 Likes

Tommertom, your answer worked for me too, thanks!

1 Like