SQLite Error with Ionic 6 and Capacitor 3

Hi,

After recently upgrading to Ionic 6 and Capacitor 3, my app now gives an error with being unable to access the sqllite database. It gives an error on load:

E/SQLitePlugin: unexpected error, stopping db thread
java.lang.NullPointerException: Attempt to invoke interface method ‘java.lang.String io.liteglue.SQLDatabaseHandle.getLastErrorMessage()’ on a null object reference
at io.liteglue.SQLiteGlueConnection.(SQLiteGlueConnection.java:12)
at io.liteglue.SQLiteConnector.newSQLiteConnection(SQLiteConnector.java:20)
at io.sqlc.SQLiteConnectorDatabase.open(SQLiteConnectorDatabase.java:55)
at io.sqlc.SQLitePlugin.openDatabase(SQLitePlugin.java:213)
at io.sqlc.SQLitePlugin.access$000(SQLitePlugin.java:28)
at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:328)
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:923)

It isn’t all phones either, an older Samsung Galaxy J3 works fine running Android 9, white it is failing with a Moto G(9) with Android 11.

Any advice on how to resolve this?

Ionic:

Ionic CLI : 6.17.0 (C:\Users\craig\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.1.5
@angular-devkit/build-angular : 13.3.5
@angular-devkit/schematics : 13.3.5
@angular/cli : 13.3.5
@ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 3.5.1
@capacitor/android : 3.5.1
@capacitor/core : 3.5.1
@capacitor/ios : 2.5.0

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : not available
Cordova Plugins : not available

cordova-res : not installed globally
native-run : 1.5.0

System:

NodeJS : v16.15.0 (C:\Program Files\nodejs\node.exe)
npm : 8.5.5
OS : Windows 10

PS C:\Users\craig\Documents\Development\websites\weight-recording-app-5> ionic info

Ionic:

Ionic CLI : 6.17.0 (C:\Users\craig\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.1.5
@angular-devkit/build-angular : 13.3.5
@angular-devkit/schematics : 13.3.5
@angular/cli : 13.3.5
@ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 3.5.1
@capacitor/android : 3.5.1
@capacitor/core : 3.5.1
@capacitor/ios : 2.5.0

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : not available
Cordova Plugins : not available

Utility:

cordova-res : not installed globally
native-run : 1.5.0

System:

NodeJS : v16.15.0 (C:\Program Files\nodejs\node.exe)
npm : 8.5.5
OS : Windows 10

Package.json

{

“name”: “weight-recording-app-5”,

“version”: “2.1.5”,

“author”: “Ionic Framework”,

“homepage”: “https://ionicframework.com/”,

“scripts”: {

"ng": "ng",

"start": "ng serve",

"build": "BUILD_ENV=${BUILD_ENV:-local} ng build --configuration=$BUILD_ENV",

"test": "ng test",

"lint": "ng lint",

"e2e": "ng e2e"

},

“private”: true,

“dependencies”: {

"@angular/common": "~13.3.6",

"@angular/core": "~13.3.6",

"@angular/forms": "~13.3.6",

"@angular/platform-browser": "~13.3.6",

"@angular/platform-browser-dynamic": "~13.3.6",

"@angular/router": "~13.3.6",

"@awesome-cordova-plugins/in-app-browser": "^5.41.0",

"@awesome-cordova-plugins/sqlite": "^5.43.0",

"@capacitor/android": "^3.5.1",

"@capacitor/app": "^1.1.1",

"@capacitor/core": "^3.5.1",

"@capacitor/device": "^1.1.2",

"@capacitor/ios": "^2.4.7",

"@capacitor/splash-screen": "^1.2.2",

"@ionic-native/app-version": "^5.32.1",

"@ionic-native/core": "^5.32.1",

"@ionic-native/in-app-browser": "^5.32.1",

"@ionic-native/native-storage": "^5.32.1",

"@ionic-native/splash-screen": "^5.32.1",

"@ionic-native/sqlite": "^5.32.1",

"@ionic-native/status-bar": "^5.32.1",

"@ionic/angular": "^6.1.5",

"@ionic/storage-angular": "^3.0.6",

"@types/uuid": "^8.3.0",

"capacitor-secure-storage-plugin": "^0.5.1",

"cordova-plugin-inappbrowser": "^5.0.0",

"cordova-plugin-ionic": "5.4.6",

"cordova-plugin-nativestorage": "^2.3.2",

"cordova-plugin-whitelist": "^1.3.4",

"cordova-sqlite-storage": "^5.1.0",

"core-js": "^2.6.12",

"moment": "^2.29.1",

"rxjs": "^6.6.7",

"tslib": "^2.0.0",

"uuid": "^8.3.2",

"zone.js": "~0.11.5"

},

“devDependencies”: {

"@angular-devkit/build-angular": "~13.3.5",

"@angular/cli": "~13.3.5",

"@angular/compiler": "~13.3.6",

"@angular/compiler-cli": "~13.3.6",

"@angular/language-service": "~13.3.6",

"@capacitor/cli": "^3.5.1",

"@ionic/angular-toolkit": "^6.0.0",

"@types/jasmine": "~3.6.0",

"@types/jasminewd2": "^2.0.9",

"@types/node": "^12.11.1",

"jasmine-core": "~3.8.0",

"jasmine-spec-reporter": "~5.0.0",

"karma": "~6.3.19",

"karma-chrome-launcher": "~3.1.0",

"karma-coverage-istanbul-reporter": "~3.0.2",

"karma-jasmine": "~4.0.0",

"karma-jasmine-html-reporter": "^1.6.0",

"protractor": "~7.0.0",

"ts-node": "~8.3.0",

"typescript": "~4.4.4"

},

“description”: “An Ionic project”

}

It is a nice post.Thank you

Solved this by installing cordova-sqlite-storage version 6.0.0.

Seems to work for me with older and newer versions of android

1 Like

Thanks for confirming this. I only discovered this error after deploying my app for testers, and then found the the app was failing to load correctly. It took me buying a second hand Samsung A52S 5G device and plugging it in to the Android Emulator to diagnose the issue.
Running “ionic serve” for the Browser, and running it in the various Google emulator phones failed to find it too, as did my personal Android phone as well. iOS also failed to identify the issue too.

Thanks for clarifying your findings.

  • “cordova-sqlite-storage”: “^5.1.0”,
  • “cordova-sqlite-storage”: “^6.0.0”,

Not sure if this will help anyone else, but here’s the basic specs for my test device where this problem failed, and was then resolved.
Samsung A52S 5G
One UI version: 4.1
Android version: 12

I can’t believe I’ve had to come back to my answer again… I’m sure I’m not the only one who does this.