Ionic Capacitor SQLite won't initialize in Android ONLY through the Play Store

I’ve built an app for iOS and Android that uses SQLite.

It runs great in iOS, AND in Android Studio debug configuration (on emulator and device). It’s currently available in the Apple App store.

I can even build a signed release version of the .apk and install it directly on my old Galaxy S8 and all works fine.

But when I build the bundle and publish to the google play store, that version will not initialize the SQLite db (I assume).

I’m not sure what code to even include here, as I’m not sure where the failure lies.

Just hoping this situation sounds familiar to someone.

This is how I open the db:

try {
//console.log(going to create a connection)
//const db = await this.getDataBaseConnection();
const db = await this.getDataBaseConnection();

  if(db === null){
    const alert = await this.alertCtrl.create({
      header: 'Offline Database Error',
      message: 'Failed to set up offline data',
      buttons: ['OK']
    });
    await alert.present();
  }

In the situation I describe above, db===null after a fresh install from the Google Play store.

package.json dependencies:
“dependencies”: {
@angular/common”: “~12.0.1”,
@angular/core”: “~12.0.1”,
@angular/forms”: “~12.0.1”,
@angular/platform-browser”: “~12.0.1”,
@angular/platform-browser-dynamic”: “~12.0.1”,
@angular/router”: “~12.0.1”,
@auth0/auth0-angular”: “^1.11.1”,
@awesome-cordova-plugins/action-sheet”: “^5.46.0”,
@awesome-cordova-plugins/app-version”: “^5.46.0”,
@awesome-cordova-plugins/core”: “^5.46.0”,
@awesome-cordova-plugins/dialogs”: “^5.46.0”,
@awesome-cordova-plugins/launch-navigator”: “^5.46.0”,
@capacitor-community/http”: “^1.4.1”,
@capacitor-community/sqlite”: “^4.2.2”,
@capacitor/android”: “^4.0.0”,
@capacitor/app”: “^4.0.0”,
@capacitor/browser”: “^4.0.0”,
@capacitor/core”: “^4.0.0”,
@capacitor/device”: “^4.0.0”,
@capacitor/dialog”: “^4.0.0”,
@capacitor/haptics”: “^4.0.0”,
@capacitor/ios”: “^4.0.0”,
@capacitor/keyboard”: “^4.0.0”,
@capacitor/preferences”: “^4.0.0”,
@capacitor/share”: “^4.0.0”,
@capacitor/splash-screen”: “^4.0.0”,
@capacitor/status-bar”: “^4.0.0”,
@googlemaps/markerclusterer”: “^1.0.27”,
@ionic-native/android-permissions”: “^5.36.0”,
@ionic-native/call-number”: “^5.36.0”,
@ionic-native/core”: “^5.36.0”,
@ionic-native/geolocation”: “^5.36.0”,
@ionic-native/launch-navigator”: “^5.36.0”,
@ionic-native/location-accuracy”: “^5.36.0”,
@ionic-native/native-geocoder”: “^5.36.0”,
@ionic-native/network”: “^5.36.0”,
@ionic-native/status-bar”: “^5.36.0”,
@ionic-native/toast”: “^5.36.0”,
@ionic-super-tabs/angular”: “^7.0.8”,
@ionic/angular”: “^6.3.9”,
@types/hammerjs”: “^2.0.41”,
“auth0-js”: “^9.19.2”,
“call-number”: “^1.0.1”,
“chart.js”: “^3.9.1”,
“cordova-plugin-actionsheet”: “^2.3.3”,
“cordova-plugin-android-permissions”: “^1.1.5”,
“cordova-plugin-app-version”: “^0.1.14”,
“cordova-plugin-dialogs”: “^2.0.2”,
“cordova-plugin-geolocation”: “^4.1.0”,
“cordova-plugin-nativegeocoder”: “^3.4.1”,
“cordova-plugin-network-information”: “^3.0.0”,
“cordova-plugin-request-location-accuracy”: “^2.3.0”,
“cordova-plugin-statusbar”: “^2.4.3”,
“cordova-plugin-x-toast”: “^2.7.3”,
“geojson”: “^0.5.0”,
“hammerjs”: “^2.0.8”,
“ionic-pullup”: “^5.0.0-beta.3”,
“json-server”: “^0.17.1”,
“mapbox-gl”: “^2.11.0”,
“node-js-marker-clusterer”: “^1.0.0”,
“rxjs”: “~6.6.0”,
“tslib”: “^2.4.1”,
“uk.co.workingedge.phonegap.plugin.launchnavigator”: “^5.0.6”,
“zone.js”: “^0.11.8”
},
“devDependencies”: {
@angular-devkit/build-angular”: “~12.0.1”,
@angular-eslint/builder”: “~12.0.0”,
@angular-eslint/eslint-plugin”: “~12.0.0”,
@angular-eslint/eslint-plugin-template”: “~12.0.0”,
@angular-eslint/template-parser”: “~12.0.0”,
@angular/cli”: “~12.0.1”,
@angular/compiler”: “~12.0.1”,
@angular/compiler-cli”: “~12.0.1”,
@angular/language-service”: “~12.0.1”,
@capacitor/cli”: “^4.0.0”,
@ionic/angular-toolkit”: “^4.0.0”,
@types/google.maps”: “^3.50.5”,
@types/googlemaps”: “^3.43.3”,
@types/jasmine”: “~3.6.0”,
@types/jasminewd2”: “^2.0.10”,
@types/node”: “^12.20.55”,
@typescript-eslint/eslint-plugin”: “4.16.1”,
@typescript-eslint/parser”: “4.16.1”,
“eslint”: “^7.32.0”,
“eslint-plugin-import”: “2.22.1”,
“eslint-plugin-jsdoc”: “30.7.6”,
“eslint-plugin-prefer-arrow”: “1.2.2”,
“jasmine-core”: “~3.7.1”,
“jasmine-spec-reporter”: “~5.0.0”,
“karma”: “^6.4.1”,
“karma-chrome-launcher”: “^3.1.1”,
“karma-coverage”: “~2.0.3”,
“karma-coverage-istanbul-reporter”: “~3.0.2”,
“karma-jasmine”: “^4.0.2”,
“karma-jasmine-html-reporter”: “^1.7.0”,
“protractor”: “~7.0.0”,
“ts-node”: “~8.3.0”,
“typescript”: “~4.2.4”
},

So part of, or most of the problem was that the app’s initial release did not use a sqlite database, it was added as a feature update in the app.

I guess Google Play, when you publish a newer version, uses archived fragments of the app bundle to keep updates small or something like that? So it didn’t know it needed to copy or create a new database on update.

I tried putting an empty copy of the .db in assets/ but that still didn’t do it.

Ultimately changing this:
android:allowBackup=“true”

to this:
android:allowBackup=“false”

Now it requires a clean install of the app from the Play Store and it works as expected.