Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
henrytranter opened this issue Oct 18, 2021 · 25 comments

Comments

@henrytranter
Copy link

Hello,

We ran into the issue: #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
Copy link

bitboxfw commented Oct 22, 2021

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
Copy link

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
Copy link
Author

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

@EmmanuelJego
Copy link

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
Copy link

KishanDasani commented Oct 28, 2021

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
Copy link

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
Copy link

Afridi1288 commented Nov 10, 2021

@KishanDasani Facing same issue

15B95B09-CBC9-4CE2-8647-C16553E6C1F8

@brodycj
Copy link
Contributor

brodycj commented Nov 11, 2021

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
Copy link

etcho commented Nov 12, 2021

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
Copy link

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
Copy link

etcho commented Nov 13, 2021

@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
Copy link

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
Copy link

@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
Copy link

YuriZem commented Jan 18, 2022

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

mirko77 commented Jun 29, 2022

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 using androidDatabaseProvider: 'system' to the version using it, will that make any difference to the existing data?

@xeux
Copy link

xeux commented Sep 19, 2022

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

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

@sithwarrior
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests