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

Android SDK Target 30 + OPEN database: x FAILED #954

Closed
jumamfa opened this issue Oct 2, 2020 · 55 comments
Closed

Android SDK Target 30 + OPEN database: x FAILED #954

jumamfa opened this issue Oct 2, 2020 · 55 comments
Assignees

Comments

@jumamfa
Copy link

jumamfa commented Oct 2, 2020

Hello,

Setting the target android SDK value to 30 results in the (normally working fine) plugin to fail when opening the database.

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

If I set the SDK value to < 30, it suddenly starts working again.

Cordova: 10
Android: 9
Ionic Storage: 2.3.1
Cordova SQLite Storage: 5.1.0

Thanks

@jumamfa
Copy link
Author

jumamfa commented Oct 2, 2020

@brodybits sorry to tag directly, but do you have any idea what could be causing this? I've noticed if I provide androidDatabaseProvider: 'system', it begins to work again however I'm using Ionic Storage and don't have that level of control / flexibility. I've also tried to go direct and use the SQLite plugin and bypass the Ionic Storage code, but the data that was once stored in SQLite no longer exists, I'm assuming because a different provider is used...

@jainank
Copy link

jainank commented Oct 27, 2020

I am also facing the same issue on Android 11 (Api 30) however it works fine for (API 29).
Here is my analysis:

following code returns negative int value
SQLiteNative.sqlc_db_open(this.dbfilename, this.openflags)
in file
https://github.com/liteglue/Android-sqlite-connector/blob/master/src/io/liteglue/SQLGDatabaseHandle.java
Line 14

Due to which https://github.com/liteglue/Android-sqlite-connector/blob/master/src/io/liteglue/SQLiteGlueConnection.java
line 12 throws Error.

@luissilvaos
Copy link

It's the same issue reported here: brodycj/cordova-sqlite-storage-dependencies#3

The plugin is not working as expected on Android 11 devices.

luissilvaos added a commit to OutSystems/Cordova-sqlite-storage that referenced this issue Nov 19, 2020
The current version of the plugin is not able to open databases when targeting the SDK 30
and running on devices with Android 11.
The issue was already reported brodycj/cordova-sqlite-storage-dependencies#3
and storesafe#954
From what I was able to understand, it is related with the permissions changes on Android 11,
where the SQLite is unable to open the database file using native C primitive `sqlite3_open_v2`:
https://github.com/liteglue/Android-sqlite-connector/blob/master/src/io/liteglue/SQLGDatabaseHandle.java#L14
https://github.com/liteglue/Android-sqlite-connector/blob/master/src/io/liteglue/SQLiteNative.java#L60
https://github.com/liteglue/Android-sqlite-native-driver/blob/master/native/sqlc.c#L40
causing the handler to crash with a NullPointerException when throwing an exception
https://github.com/liteglue/Android-sqlite-connector/blob/master/src/io/liteglue/SQLiteGlueConnection.java#L12

Summing up, this hotfix will enable the usage of the default Android database provider for Android 11 only,
by setting the `oldImpl` to `true`, which is the same behaviour of using the `androidDatabaseProvider: 'system'`
setting at the javascript side.

References https://outsystemsrd.atlassian.net/browse/RNMT-4515
@brodycj brodycj pinned this issue Nov 20, 2020
@brodycj brodycj self-assigned this Nov 20, 2020
@brodycj
Copy link
Contributor

brodycj commented Nov 20, 2020

Thanks for reporting, I will investigate this in the near future. I will also investigate if this is an issue in cordova-sqlcipher-adapter, which is always using a custom SQLCipher build also based on SQLite.

@kinor
Copy link

kinor commented Jan 25, 2021

@brodybits @jfrumar Has this issue been addressed? We are also seeing the same problem. Thanks!

@laurentperez
Copy link

Hi. Same here. Is there work planned on this ? Given the merged fork at OutSystems/Android-sqlite-native-driver#1 + the sqlcipher investigation above.

Thanks
@brodybits

@brodycj
Copy link
Contributor

brodycj commented Feb 8, 2021

Thanks for the ping, I will definitely work on this with high priority. Please ping me if you do not see progress in the next 2-3 weeks.

@brodycj
Copy link
Contributor

brodycj commented Feb 9, 2021

I tried Android SDK 30 together with Android 11 from this branch of cordova-sqlite-test-app: https://github.com/brodybits/cordova-sqlite-test-app/tree/android-sdk-30-test

I am able to use the buttons to add record and show record count still with no problems on an Android 11 emulator. I may need a some time to obtain an Android 11 device for further testing.

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

This error indicates to me that the app opens a database and immediately starts one or more transactions. I recommend that you consider waiting for the openDatabase success callback as documented.

@studioromeo
Copy link

Hey!

I'm hoping I can chip in with some useful info but take this with a pinch of salt as I've not sanity checked this.

When setting the targetSDK to 30 as the author mentions it would fail to open the database on Android 11. It wouldn't happen on all devices though. We saw it on the latest generation of Pixels most notably so the 4A, 4A (5G) and 5.

We tried the Pixel 4 & 3A and they worked fine. All devices tested were on A11.

Sorry I know that's probably not much use but hopefully helps a little 😅

@jlandrum
Copy link

I can confirm that setting the Target API to 29 does indeed solve the problem. Using the callback does not - it will in fact call the error callback, though it is still best practices to do this anyway and I'd recommend implementing it this way when possible.

I'm not sure what actually triggers it though as indeed, I tested on numerous Android 11 devices with no issue except it fails on the Galaxy S20+.

@kensho-seto
Copy link

I have the same problem.
DB error occurs on Pixcel 4a (android11). If it is a simulator, no error will occur.

Since August 2021, google has required SDK30 support. So I don't think it's very good to lower the sdk version.
https://developer.android.com/distribute/best-practices/develop/target-sdk

@heffthedev
Copy link

I can confirm that the issue also happens on the Samsung S21 Ultra 5G and the Xiaomi Mi Note 10. I'd love to avoid lowering the target SDK if in any way possible.

@magynhard
Copy link

@brodybits
Also having the same problem, just by initializing the DB and read some data.

Everythinkg worked fine before SDK30 / Android 11.

I am able to use the buttons to add record and show record count still with no problems on an Android 11 emulator. I may need a some time to obtain an Android 11 device for further testing.

You could use 30 Mintues for free at https://www.browserstack.com using a real remote device. You just need to upload the APK and can choose between lots of real devices. For OpenSource projects like yours, you can ask for the OpenSource program to get a free full lifetime access:
https://www.browserstack.com/open-source

I tried a lot these days, also to reproduce the bug in your test app.

After a long time trying and getting crazy, I have found the problem: There was a typo in your test app.

I created a PR brodycj/cordova-sqlite-test-app#7 and hope you can fix the problem soon, as i really do not want to drop your plugin from my project as i have to create a new release of my app soon.

Maybe you can work together or be inspired by the guys of
OutSystems#7
OutSystems#8
OutSystems#9

@magynhard
Copy link

Additional Debug Information:

03-19 12:44:53.121 E/SQLitePlugin(16860): unexpected error, stopping db thread
03-19 12:44:53.121 E/SQLitePlugin(16860): java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String io.liteglue.SQLDatabaseHandle.getLastErrorMessage()' on a null object reference
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at io.liteglue.SQLiteGlueConnection.<init>(SQLiteGlueConnection.java:12)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at io.liteglue.SQLiteConnector.newSQLiteConnection(SQLiteConnector.java:20)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at io.sqlc.SQLiteConnectorDatabase.open(SQLiteConnectorDatabase.java:55)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at io.sqlc.SQLitePlugin.openDatabase(SQLitePlugin.java:213)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at io.sqlc.SQLitePlugin.access$000(SQLitePlugin.java:28)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:328)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
03-19 12:44:53.121 E/SQLitePlugin(16860): 	at java.lang.Thread.run(Thread.java:923)

@brodycj
Copy link
Contributor

brodycj commented Mar 19, 2021

@magynhard you should see that I have already merged your PR on the test app. I did reach out to browserstack.com for the open source testing and hope to end up with some positive results.

It looks to me like OutSystems solved it by using a complex type in the NDK library, and I am thinking about incorporating their updates if I can get some confirmation from others that it will actually solve this problem. The one thing is that they have dropped Android 5.1 support, which I am not yet ready to do on this plugin.

@brodycj
Copy link
Contributor

brodycj commented Mar 19, 2021

Another quick update: Browser Stack has approved me for the open source testing for 1 year. Thanks to @magynhard for the suggestion!

I will start using Browser Stack to test on multiple Android 11 devices. I will try both the existing plugin and a version with the fixes from OutSystems#9. I may need a few days to have some meaningful results worth posting.

Any input from the user community would be much appreciated on this issue.

@luissilvaos
Copy link

Hello guys,
I can confirm you that OutSystems#9 fixed the issue with Android 11 devices.

@brodycj
Copy link
Contributor

brodycj commented Mar 19, 2021

Thanks!

I have tested on Pixel 5 with help from Browser Stack, reproduced the issue, and it seems to be solved by the OutSystems fork.

I would like to do some more testing before updating this plugin.


P.S. I tested the OutSystems fork from here: https://github.com/brodybits/cordova-sqlite-test-app/tree/android-sdk-30-outsystems-fork-test


P.P.S. The actual solution is in the following PRs:

The details are in the commit message of this commit: OutSystems/Android-sqlite-native-driver@6a19159


P.S. 3: Adding reference to a corresponding discussion on cordova-android: apache/cordova-android#1006

Planning to bump the default Android SDK Target to 30, but not until cordova-android 10.0.0.

@KishanDasani
Copy link

KishanDasani commented Oct 27, 2021

Hello there,

Facing the same issue with cordova-sqlite-storage version 5.1.0.

But when updated to newest version i.e 6.0.0 this happens. (snapshot attached)

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

Screenshot_1635341174

@abhiways
Copy link

Remove Platform Android and add platform again with version tag to latest

ionic cordova platform add android@10 >> For ionic

@KishanDasani
Copy link

KishanDasani commented Oct 28, 2021

@abhiways Thank you for the suggestion.
But this didn't helped
I tried cordova-android 10.0.0 with both plugin versions i.e. 5.1.0 and 6.0.0.

@prasuncnair
Copy link

I am also seeing similar issue as @KishanDasani for cordova-android 10.0.0 with 6.0.0
Application Error - The connection to server was unsuccessful.

@SajevLucksman
Copy link

@brodybits Getting this issue for Andoroid platform version 8.1.0 and "cordova-sqlite-storage": "^6.0.0" ```
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String io.liteglue.SQLDatabaseHandle.getLastErrorMessage()' on a null object reference
03-19 12:44:53.121 E/SQLitePlugin(16860): at io.liteglue.SQLiteGlueConnection.(SQLiteGlueConnection.java:12)

@KishanDasani
Copy link

@brodybits
Sorry to tag directly
But can you kindly look into this?
as we are in November and target to API 30 is must

@brodycj
Copy link
Contributor

brodycj commented Nov 4, 2021

Please check the following:

  • all plugins are configured in package.json
  • no plugins are listed in config.xml
  • you are using latest cordova-sqlite-storage version (6.0.0 at this point)
  • no other SQLite plugin versions are configured

Completely remove both plugins and platforms directories from your workarea.

I would also recommend removing configuration of Cordova platform versions.

Then do cordova platform add android@latest

@exequielc
Copy link

Same issue here

I'm using version 6.0.0 with android 11 (sdk 30)

And the status is "cant open database" only on some physical phones (samsung s21 or xiami redmi 9) 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

@KishanDasani
Copy link

KishanDasani commented Nov 9, 2021

Please check the following:

  • all plugins are configured in package.json
  • no plugins are listed in config.xml
  • you are using latest cordova-sqlite-storage version (6.0.0 at this point)
  • no other SQLite plugin versions are configured

Completely remove both plugins and platforms directories from your workarea.

I would also recommend removing configuration of Cordova platform versions.

Then do cordova platform add android@latest

Thank you for your reply @brodybits
I've tried this. Unfortunately, this didn't even help.

@Afridi1288
Copy link

Afridi1288 commented Nov 10, 2021

@brodybits Facing the same issue. Release build with cordova-sqlite-storage v6.0.0 is crashing. Please help to fix this issue.

15B95B09-CBC9-4CE2-8647-C16553E6C1F8

@Afridi1288
Copy link

Please check the following:

  • all plugins are configured in package.json
  • no plugins are listed in config.xml
  • you are using latest cordova-sqlite-storage version (6.0.0 at this point)
  • no other SQLite plugin versions are configured

Completely remove both plugins and platforms directories from your workarea.
I would also recommend removing configuration of Cordova platform versions.
Then do cordova platform add android@latest

Thank you for your reply @brodybits I've tried this. Unfortunately, this didn't even help.

@KishanDasani Did you find any other solution??

@KishanDasani
Copy link

Please check the following:

  • all plugins are configured in package.json
  • no plugins are listed in config.xml
  • you are using latest cordova-sqlite-storage version (6.0.0 at this point)
  • no other SQLite plugin versions are configured

Completely remove both plugins and platforms directories from your workarea.
I would also recommend removing configuration of Cordova platform versions.
Then do cordova platform add android@latest

Thank you for your reply @brodybits I've tried this. Unfortunately, this didn't even help.

@KishanDasani Did you find any other solution??

Hi, @Afridi1288
Not yet, this has become a headache for some days.

@bdlneto
Copy link

bdlneto commented Nov 10, 2021

Hello

I am also having the same problem, Android 11 and cordova-sqlite-plugin 6.0.0. Already removed and installed platforms and plugins, but my screen just shows a white screen and throws the error ""OPEN database: _ionicstorage FAILED, aborting any pending transactions"

"

@brodycj
Copy link
Contributor

brodycj commented Nov 11, 2021

See #991 (comment):

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.

@gerhartz
Copy link

Please check the following:

all plugins are configured in package.json
no plugins are listed in config.xml
you are using latest cordova-sqlite-storage version (6.0.0 at this point)
no other SQLite plugin versions are configured
Completely remove both plugins and platforms directories from your workarea.

I would also recommend removing configuration of Cordova platform versions.

Then do cordova platform add android@latest

These steps worked AFTER I deleted my local repo and then ran cordova platform add android@latest on a fresh local copy worked for me. Trying to uninstall/reinstall cordova plugins on my original repo did not work.

Ionic:

Ionic CLI : 6.13.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.6.3
@angular-devkit/build-angular : 0.1001.7
@angular-devkit/schematics : 10.2.3
@angular/cli : 10.2.3
@ionic/angular-toolkit : 2.3.3

We pushed a new app version with API 30 and some android users had a white screen when launching app. Previous versions worked for them until API 30. Running the above steps on a fresh repo worked and allowed us to get a new build into production.

@KishanDasani
Copy link

KishanDasani commented Nov 22, 2021

Please check the following:
all plugins are configured in package.json
no plugins are listed in config.xml
you are using latest cordova-sqlite-storage version (6.0.0 at this point)
no other SQLite plugin versions are configured
Completely remove both plugins and platforms directories from your workarea.
I would also recommend removing configuration of Cordova platform versions.
Then do cordova platform add android@latest

These steps worked AFTER I deleted my local repo and then ran cordova platform add android@latest on a fresh local copy worked for me. Trying to uninstall/reinstall cordova plugins on my original repo did not work.
Ionic:
Ionic CLI : 6.13.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.6.3 @angular-devkit/build-angular : 0.1001.7 @angular-devkit/schematics : 10.2.3 @angular/cli : 10.2.3 @ionic/angular-toolkit : 2.3.3
We pushed a new app version with API 30 and some android users had a white screen when launching app. Previous versions worked for them until API 30. Running the above steps on a fresh repo worked and allowed us to get a new build into production.

Hey mate, I tried this, but unfortunately this didn't even work.

Ionic:

Ionic CLI : 3.9.0
Ionic Framework : @ionic/angular 3.9.10
@angular/cli : 1.2.5

@krishna711
Copy link

Hello @gerhartz What do you mean "deleted my local repo" . Can you provide exact steps. I am also facing same issue and applied all above steps did not solve issue. Pain is that it is happening on release version only. debug version work well everywhere. These seems known issue with Android 11. Kindly, help with steps you followed to solve issue.

@gerhartz
Copy link

gerhartz commented Nov 30, 2021 via email

@krishna711
Copy link

Thanks @gerhartz for quick response. My issue is resolved some other way. I just uninstalled plugin to resolve this issue. This may not be ideal solution for everyone. For me cordova-sqlite-storage plugin was only used to support ionic storage. In absence of this plugin ionic storage will use localstorage instead or indexdb whichever is available.

Uninstall plugin
Remove android platform
Add android platform again

@mantovanigo
Copy link

mantovanigo commented Feb 3, 2022

We've faced this issue in production, after changing from API level 29 to 30 due to recent Google requirements. The app was opening with a blank screen but only for some users with Android 11 (phone model Samsung Galaxy A71 appeared to be most affected, also Pixel 5). The app is old, Ionic v4 with Angular 8.1... No "application error" message, only blank screen (admob ads on native activities worked fine nonetheless, which made users get mad and submit 1-star reviews).

After digging into logcat for hours, we found the "OPEN database: _ionicstorage FAILED, aborting any pending transactions" error along with:
Open sqlite db: /data/user/0/com.example.app/databases/_ionicstorage
E/SQLitePlugin(24653): unexpected error, stopping db thread
E/SQLitePlugin(24653): java.lang.NullPointerException: Attempt to invoke interface method java.lang.String io.liteglue.SQLDatabaseHandle.getLastErrorMessage() on a null object reference
Considering that we have the most basic need for data storage (only a couple of basic get/set operations), the solution was to remove this plugin and rely only on @ionic/storage. Retested on problematic device and the app started to work again.

@laurentperez
Copy link

Unsure removing the plugin is a good idea @mantovanigo @krishna711

Otherwise you could fall into the pitfalls mentionned here https://ionicframework.com/docs/v3/storage/ (if you drop sqlite)

@AustineA
Copy link

AustineA commented Feb 8, 2022

This is what worked for me.

ionic cordova plugin remove cordova-sqlite-storage followed by ionic cordova plugin add cordova-sqlite-storage

@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.

@justin-mccabe
Copy link

For anyone still running into this issue, I've been fighting with it for far too long but I have come to a solution. The issue is on physical android 11 and 12 devices (I haven't tested lower). The fix is in version 6.0.0, but was only seen after deleting any prior project files. Our project is a large code base, so while you might encounter a better solution, this worked for me.

  1. Pull down a fresh repo of your project.
  2. Go into your package.json and be sure you have "cordova-sqlite-storage": "6.0.0". No other version or references to this plugin.
  3. Go into your cordova "plugins" folder. If you have an existing "cordova-sqlite-storage" folder inside, delete it.
  4. Install your npm packages for your project, npm i,
  5. Build and prepare your app as you normally do, ionic cordova build android and ionic cordova prepare android
  6. If you have any current app data on your physical device, clear the app data and cache. Otherwise you may get an error where it cannot find tables that it thinks already exist.
  7. Run it via android studio or however you prefer.

Hope that helps.

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

No branches or pull requests