andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.75k stars 521 forks source link

Android 11 Open database failed. Could not open database on some Android devices #462

Open TheGameNewWorldOrder opened 3 years ago

TheGameNewWorldOrder commented 3 years ago

Hi,

Some of our users have reported an issue related to the SQLite lib. After updating their phone's OS( Color OS) to 11(Android 11), SQLite operation is broken. In debug mode I see below error:

OPEN database: StorageExtension.db failed, aborting any pending transactions and following if trying to call any transaction:

error: openDatabase {"dblocation": "nosync", "location": "default", "name": "StorageExtension.db"} [[Error: Could not open database]]

I have verified the app and plugin work fine on Color OS 7 and 10, but broken on 11.

Expected Behavior

DB connection is as usual and DB can be opened.

Current Behavior

Opening DB failed

Possible Solution

Related to Android 11?

Steps to Reproduce (for bugs)

Example code im using:

`

SQLite.enablePromise(true); SQLite.DEBUG(true);

const init = async () => { await SQLite.echoTest(); db = await SQLite.openDatabase({ name: DATABASE_NAME, location: 'default', }); await createTables(db); }; `

Note that this code works fine on older Color OS and other Android phone like Samsung and Huawei

Your Environment

Debug logs

image

As shown above, the db was created but at /data/data//databases/

I have also tried the solution to create pre-populated DB but with no luck: https://medium.com/infinitbility/react-native-sqlite-storage-422503634dd2

Any idea why this is happening? We also have users on OnePlus and Pixel reporting the same problem.

castalonirenz commented 2 years ago

Due to maintainer inactivity to accept PRs I've created another package based on this package with new android native libraries for API 30 available to use: https://www.npmjs.com/package/react-native-sqlite-storage-api30 https://github.com/Ehsan0Hejazi/react-native-sqlite-storage-api30 npm i react-native-sqlite-storage-api30

Can you tell us what are the changes you have done here so we can have an idea? thanks in advance

I have added new android native libraries patches which is under /platforms/android-native/libs other parts are remained the same, so now you can switch your android target API to 30 and there will be no bugs and errors

The app is crashing on apk release

Please create an issue with more details under the package github so we can track it

image

Here is the logcat from apk release build

Ehsan0Hejazi commented 2 years ago

ok I think I found the problem just follow this

in react-native.config.js

your dependencies should be as follows

dependencies: {
      "react-native-sqlite-storage-api30": {
        platforms: {
          android: {
            sourceDir:
              "../node_modules/react-native-sqlite-storage-api30/platforms/android-native",
            packageImportPath: "import io.liteglue.SQLitePluginPackage;",
            packageInstance: "new SQLitePluginPackage()"
          }
        }
      }
    }

you are exporting "react-native-sqlite-storage" while you need to export "react-native-sqlite-storage-api30"

let me know if your problem is solved

amirkhanzada51 commented 2 years ago

I am running into an identical problem.

Related to this and PR #492 .... curiously enough ... I removed the custom SQLite build and used the device's SQLite and I got it to work with my existing code.

i.e. I removed this from the react-native.config.js and it worked.

    "react-native-sqlite-storage": {
      platforms: {
        android: {
          sourceDir:
            "../node_modules/react-native-sqlite-storage/platforms/android-native",
          packageImportPath: "import io.liteglue.SQLitePluginPackage;",
          packageInstance: "new SQLitePluginPackage()"
        }
      }
    }

Hey, you save my soul. after 2 days of headache finally, solve the problem.

Raj797979 commented 1 year ago

can you guide me cause i'm getting same issue with android version 11 and above

usmanmalik333 commented 1 year ago

still not working on android 11 any solution ? if we removed the dependencies then it not working on other android version

amf-paulinho commented 1 year ago

I am having same problem. Is this still open?

if I want to use SQLite that comes with the library Android 11 cant open the database, If I use the Device SQLite lots of Android 10 will crash.

this is my config file:

module.exports = {
  dependencies: {
    'react-native-sqlite-storage': {
      platforms: {
        ios: {},
        android: {
          sourceDir: '../node_modules/react-native-sqlite-storage/platforms/android-native',
          packageImportPath: 'import io.liteglue.SQLitePluginPackage;',
          packageInstance: 'new SQLitePluginPackage()',
        },
      },
    },
  },
};

Removing it solves for Android 11 however android 10 will not work. Device I am testing are Motorola One 5G Ace - Android 11 and Galaxy S9+ Android 10 (also another motorola One using Android 10 )

There is no solution still ?

shiroze commented 1 year ago

I am running into an identical problem.

Related to this and PR #492 .... curiously enough ... I removed the custom SQLite build and used the device's SQLite and I got it to work with my existing code.

i.e. I removed this from the react-native.config.js and it worked.

    "react-native-sqlite-storage": {
      platforms: {
        android: {
          sourceDir:
            "../node_modules/react-native-sqlite-storage/platforms/android-native",
          packageImportPath: "import io.liteglue.SQLitePluginPackage;",
          packageInstance: "new SQLitePluginPackage()"
        }
      }
    }

Not working on Android 11+ on Device Redmi Note 9 Pro

LaGregance commented 1 year ago

Due to maintainer inactivity to accept PRs I've created another package based on this package with new android native libraries for API 30 available to use:

https://www.npmjs.com/package/react-native-sqlite-storage-api30 https://github.com/Ehsan0Hejazi/react-native-sqlite-storage-api30

npm i react-native-sqlite-storage-api30

Thanks a lot, it's work for me, just note in order to not break others package that are based on it, you can install the package like that:

yarn add react-native-sqlite-storage@npm:react-native-sqlite-storage-api30

So you can refer to it using standard import XXX from 'react-native-sqlite-storage'

hengkx commented 1 year ago

Do you have any solutions?

Mohammed-Aljasem commented 4 months ago

any updates ?

LaGregance commented 2 months ago

Hi,

I've created a fork of this repository that bring multiple things:

The fork is a drop in remplacement of this repository.

To see it, click here: https://www.npmjs.com/package/@boltcode/react-native-sqlite-storage

If you want to understand what I've done in this fork, there is a documentation about it.

Have a good day.