storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.14k stars 713 forks source link

Failure to open database on some phones, cordova-sqlite-storage version 6.0.0 #991

Open henrytranter opened 2 years ago

henrytranter commented 2 years ago

Hello,

We ran into the issue: https://github.com/storesafe/cordova-sqlite-storage/issues/954 a couple of months ago, but installing version 6.0.0 of this plugin seemed to fix that issue.

However, the same thing has started happening on the few devices it was happening prior to upgrading to version 6.0.0. I am not sure if there has been an Android 11 update recently that might have caused this.

"OPEN database: _ionicstorage FAILED, aborting any pending transactions"

Cordova: 10 Android: 11 Ionic Storage: 2.3.1 Cordova SQLite Storage: 6.0.0

bitboxfw commented 2 years ago

We have exactly the same problem on a Pixel 5. Pixel 3a and simulator working fine. Issue #954 does not solve the problem in our case.

Cordova: 10.0.0 Android: 12 (Release) Ionic Storage: 2.2.0 (same with 2.3.1) Cordova SQLite Storage: 6.0.0

bitboxfw commented 2 years ago

Update:

In my case "npm i cordova-sqlite-storage@6.0.0" updated the package in node_modules, but not in the folder plugins. So i had to uninstall the plugin with cordova and then install it again with cordova:

Uninstall: ionic cordova plugin rm cordova-sqlite-storage Install: ionic cordova plugin add cordova-sqlite-storage@6.0.0

Now, finally, everything works as expected.

henrytranter commented 2 years ago

@bitboxfw no luck for us on this. Same issue.

EmmanuelJego commented 2 years ago

Update:

In my case "npm i cordova-sqlite-storage@6.0.0" updated the package in node_modules, but not in the folder plugins. So i had to uninstall the plugin with cordova and then install it again with cordova:

Uninstall: ionic cordova plugin rm cordova-sqlite-storage Install: ionic cordova plugin add cordova-sqlite-storage@6.0.0

Now, finally, everything works as expected.

Thanks @bitboxfw, it worked! 👍

KishanDasani commented 2 years ago

Hi there,

I'm facing this issue with plugin version 5.1.0 and tried using version 6.0.0 as commented in #954

But it leads to the situation which can be seen in the snapshot attached.

Also tried updating cordova-android to 10.0.0, but no luck.

Seeking help as stuck on this issue and have to provide support for android 11.

Also, please note that this behaviour happens on signed release apk, not on debug apk.

Screenshot_1635341174

exequielc commented 2 years ago

Same issue here

using version 6.0.0 with android 11 (sdk 30)

and the status is "cant open database" only on physical phones but on emulator works

Ionic:

Ionic CLI : 5.4.16 Ionic Framework : @ionic/angular 4.11.7 @angular-devkit/build-angular : 12.2.13 @angular-devkit/schematics : 12.2.13 @angular/cli : 9.1.13 @ionic/angular-toolkit : 4.0.0

Cordova:

Cordova CLI : 10.0.0 (cordova-lib@10.1.0) Cordova Platforms : android 10.1.1, ios 6.1.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 20 other plugins)

Utility:

cordova-res : 0.15.3 native-run (update available: 1.5.0) : 1.4.0

System:

Android SDK Tools : 26.1.1 (/Users/exequielcatalani/Library/Android/sdk) ios-sim : 8.0.2 NodeJS : v14.17.0 (/usr/local/bin/node) npm : 6.14.13 OS : macOS Big Sur Xcode : Xcode 13.1 Build version 13A1030d

Afridi1288 commented 2 years ago

@KishanDasani Facing same issue

15B95B09-CBC9-4CE2-8647-C16553E6C1F8

brodybits commented 2 years ago

I am now wondering if this may have something to do with Ionic. In general, Apache Cordova, this plugin, and other plugins expect the JavaScript to wait for the deviceready event before attempting any plugin access. But I have seen issues before where things started breaking with newer frameworks and devices.

I would recommend an approach of starting with a new Ionic project and trying one thing at a time to see what does and does not work with the newer Android versions.

etcho commented 2 years ago

I don't know if it's about the same problem, but my app couldn't connect to the database after I changed the targetSdkVersion to 30. After some heart attacks with a broken version on production (it only crashed on some devices), adding androidDatabaseProvider: 'system' to the openDatabase function solved the problem.

KishanDasani commented 2 years ago

I don't know if it's about the same problem, but my app couldn't connect to the database after I changed the targetSdkVersion to 30. After some heart attacks with a broken version on production (it only crashed on some devices), adding androidDatabaseProvider: 'system' to the openDatabase function solved the problem.

Hey mate, I am not seeing openDatabase function available. I am currently using create method which doesn't have androidDatabaseProvider option. Can you please say which version of cordova-sqlite-storage and @ionic-native/sqlite you are using?

etcho commented 2 years ago

@KishanDasani I don't use ionic, but it seems irrelevant here. I'm talking about when opening the database, like this: database = window.sqlitePlugin.openDatabase({ name: db_name, location: 'default', androidDatabaseProvider: 'system' }, callback, function (err) { console.log(JSON.stringify(err)); });

KishanDasani commented 2 years ago

database = window.sqlitePlugin.openDatabase({ name: db_name, location: 'default', androidDatabaseProvider: 'system' }, callback, function (err) { console.log(JSON.stringify(err)); });

Hey buddy, I replaced my create method usage with openDatabase method, but still the app is not working.

wilsolutions commented 2 years ago

@KishanDasani I don't use ionic, but it seems irrelevant here. I'm talking about when opening the database, like this: database = window.sqlitePlugin.openDatabase({ name: db_name, location: 'default', androidDatabaseProvider: 'system' }, callback, function (err) { console.log(JSON.stringify(err)); });

Thank you, this solved to me. cordova-android 9 + ionic + "cordova-sqlite-storage": "3.4.0",

YuriZem commented 2 years ago

database = window.sqlitePlugin.openDatabase({ name: db_name, location: 'default', androidDatabaseProvider: 'system' }, callback, function (err) { console.log(JSON.stringify(err)); });

Hey buddy, I replaced my create method usage with openDatabase method, but still the app is not working.

hello did you find any solution? I'm facing this problem for some time with the A31 device

the solutions above didn't work or I did something wrong

-cordova-sqlite-storage@6.0.0 -cordova@11.0.0 -cordova-android@10.1.1

Romulogss commented 2 years ago

Has any solution been found? I'm having the same problem and I've already followed all the guidelines on using cordova-sqlite-storage@6.0.0 and the problem persists. When I try to use cordova-sqlite-storage@5 the DB does not open on android 11. native-run : 1.5.0 Android SDK Tools : 26.1.1-32.0.0 NodeJS : v14.15.0 npm : 6.14.16 OS : Windows 10

Willian199 commented 2 years ago

I have the same problem. After some research and testing, I managed to work on my phone. But some devices keep with this issue. I made a fork, feel free to test. here

Romulogss commented 2 years ago

I have the same problem. After some research and testing, I managed to work on my phone. But some devices keep with this issue. I made a fork, feel free to test. here

It worked but I needed to change:

SQLiteAndroidDatabase mydb = old_impl ? new SQLiteAndroidDatabase() : new SQLiteConnectorDatabase();
            try {
                mydb.open(dbfile);
            } catch (Exception e) {
                if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) &&
                        mydb instanceof SQLiteConnectorDatabase &&
                        (e instanceof NullPointerException || e instanceof java.sql.SQLException)) {
                    Log.v(SQLitePlugin.class.getSimpleName(), "Applying hotfix for Android 11+");
                    mydb = new SQLiteAndroidDatabase();
                    mydb.open(dbfile);
                }
                else{
                    throw e;
                }
            }

To

SQLiteAndroidDatabase mydb = old_impl ? new SQLiteAndroidDatabase() : new SQLiteConnectorDatabase();
            try {
                mydb.open(dbfile);
            } catch (Exception e) {
                if ((Build.VERSION.SDK_INT >= 30 || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) &&
                        mydb instanceof SQLiteConnectorDatabase &&
                        (e instanceof NullPointerException || e instanceof java.sql.SQLException)) {
                    Log.v(SQLitePlugin.class.getSimpleName(), "Applying hotfix for Android 11+");
                    mydb = new SQLiteAndroidDatabase();
                    mydb.open(dbfile);
                }
                else{
                    throw e;
                }
            }
KishanDasani commented 2 years ago

Hi there, In case anyone still facing this issue of app not working on android 11 phones because of sqlite, and if you've enabled proguard in your app, make sure you add some of the SQL classes in that proguard file.

My issue got resolved when I modified my proguard file with some SQL classes.

Romulogss commented 2 years ago

Hi there, In case anyone still facing this issue of app not working on android 11 phones because of sqlite, and if you've enabled proguard in your app, make sure you add some of the SQL classes in that proguard file.

My issue got resolved when I modified my proguard file with some SQL classes.

Could you show me your proguard file? I put the entire io.sqlc.** package in my proguard file and the problem continues.

KishanDasani commented 2 years ago

Hi there, In case anyone still facing this issue of app not working on android 11 phones because of sqlite, and if you've enabled proguard in your app, make sure you add some of the SQL classes in that proguard file. My issue got resolved when I modified my proguard file with some SQL classes.

Could you show me your proguard file? I put the entire io.sqlc.** package in my proguard file and the problem continues.

Something like this -keep class org.sqlite.** { *; } -keep class org.sqlite.database.** { *; } -keep class io.sqlc.** {*;} -keep class io.liteglue.** {*;}

Romulogss commented 2 years ago

Hi there, In case anyone still facing this issue of app not working on android 11 phones because of sqlite, and if you've enabled proguard in your app, make sure you add some of the SQL classes in that proguard file. My issue got resolved when I modified my proguard file with some SQL classes.

Could you show me your proguard file? I put the entire io.sqlc.** package in my proguard file and the problem continues.

Something like this -keep class org.sqlite.** { *; } -keep class org.sqlite.database.** { *; } -keep class io.sqlc.** {*;} -keep class io.liteglue.** {*;}

This works for me, thanks

mirko77 commented 1 year ago

I don't know if it's about the same problem, but my app couldn't connect to the database after I changed the targetSdkVersion to 30. After some heart attacks with a broken version on production (it only crashed on some devices), adding androidDatabaseProvider: 'system' to the openDatabase function solved the problem.

@etcho do you know if that androidDatabaseProvider parameter is backward compatible? If someone updates the app from a version NOT usingandroidDatabaseProvider: 'system' to the version using it, will that make any difference to the existing data?

xeux commented 1 year ago

I use Storage for a few strings, the solution for me was to force IndexedDB

IonicStorageModule.forRoot({ driverOrder: ['indexeddb'] }),

sithwarrior commented 1 year ago

I use Storage for a few strings, the solution for me was to force IndexedDB

IonicStorageModule.forRoot({ driverOrder: ['indexeddb'] }),

But then you are not using this plugin, you are using indexeddb from the webview instead.

mariusurbelis commented 6 months ago

Same issue. Seems to not be able to open the database when built as standalone apk and installed on an Android 14 device. Works fine when running Cordova serve android.