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( 05-13 17:27:50.200 W/System.err(18272): at org.json.JSONArray.getJSONArray( 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin.execInBackgroundAndReturnResults( 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin.runInBackground( 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin.access$000( 05-13 17:27:50.200 W/System.err(18272): at com.nolanlawson.cordova.sqlite.SQLitePlugin$ 05-13 17:27:50.200 W/System.err(18272): at android.os.Handler.handleCallback( 05-13 17:27:50.200 W/System.err(18272): at android.os.Handler.dispatchMessage( 05-13 17:27:50.200 W/System.err(18272): at android.os.Looper.loop( 05-13 17:27:50.200 W/System.err(18272): at 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…


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.




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.


Tommertom, your answer worked for me too, thanks!

1 Like