Git Product home page Git Product logo

Comments (24)

rijeshpk avatar rijeshpk commented on June 12, 2024 1

@wimZ @ileosebastian
I had similar issue when I uninstall and reinstall app. It restores old data and creates the plugin issue you mentioned. Setting allowbackup='false' fixed the issue, which excludes the old app data when reinstalling the app.
Below link has changes required to be done for older version of android and new.
https://stackoverflow.com/questions/70365809/how-to-specify-to-not-allow-any-data-backup-with-androiddataextractionrules

@jepiqueau

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ Not really an idea. May be you should try to invalidate the cache File->Invalidate Caches select all caches and invalidate and restart. and redo the full sequence

npx cap sync
npm run build
npx cap copy
npx cap open android

in Android Studio do

  • Build-> Clean Project
  • File-> Sync Project with Gradle Files
  • Build-> Rebuild Project

i never published an app to the play-store, i only develop capacitor plugins, so here i cannot help

Hope this will help

Which version of Android Studio ?

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

@jepiqueau: The rebuild as described was not successful.

Android Studio is 2023.1.1

;)

from sqlite.

ileosebastian avatar ileosebastian commented on June 12, 2024

I had the same problem, but not in production but with the app-debug that generates the ionic capacitor run android command.
Using the app made by Jepiqueau, called ionic7-angular-sqlite-starter, I have been able to solve the problem, to tell the truth, without much insight into how exactly I did it.
I thought it was a problem with the capacitor.config.ts file, but it's not. Today I needed to install Capacitor's SplashScreen for my app, installing it as the official Capacitor website suggests, and when I used it only once and re-did the app-debug, I got this message again, that is, CapacitorSQLitePlugin:null. I have uninstalled the SplashScreen plugin and returned to my previous functional build and the problem still exists.

I have been able to analyze that this only happens on certain Android devices, specifically on my physical device that has Android 12, but on Android Studio emulated devices this problem does not occur (I tried APIs 30, 31 and 32).

I've also noticed ambiguities depending on what OS I run my Ionic project on. Since it works perfectly on the physical device if I run it on Manjaro OS.

Post data: This is the first time I speak in a discussion forum here on Git hub, if I have been impertinent in any community rule, I apologize to everyone.

I have attached my package.json below:
package.json

from sqlite.

ileosebastian avatar ileosebastian commented on June 12, 2024

@jepiqueau: The rebuild as described was not successful.

Android Studio is 2023.1.1

;)

I did the same process and I got the exact same thing.

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@rijeshpk thnks for this,
@wimZ @ileosebastian Can you try what @rijeshpk proposed and tell me if it works.
otherwise there is solution to clean the cache programmatically when you re-install the app

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

@jepiqueau,
I already made these settings with same result.

BTW I use plain capacitor without framework

In order to figure out where it starts to fail, I wanted to create a minimal app and rebuild from there while phased testing
Unluckily I run into the following:

After initial setup as per: https://capacitorjs.com/docs/getting-started
then npm i @capacitor-community/sqlite
This creates a vite build.

Then I get the following result

my index.js (stripped out non-essentials)

import {CapacitorSQLite,SQLiteConnection) from '@capacitor-community/sqlite'
const _db = CapacitorSQLite
const dbName='abc'

//1
await _db.createConnection({database: dbName,encrypted: false,mode: 'no-encryption',version: 1,})

//2
await _db.open({ database: dbName })

//3
await _db.execute({database: dbName, statements: [DROP TABLE IF NOT EXIST test], values: [],})
Error:
Execute: Attempt to invoke virtual method 'java.lang.String java.lang.String.replace(java.lang.CharSequence, java.lang.CharSequence)' on a null object reference
at returnResult ((index):917:32)
at cap.fromNative ((index):899:17)
at :1:18

//4
await _db.query({database: dbName, statement: 'Select * from test', values: [], })
Error:
Query: in selectSQL cursor no such table: test: , while compiling: Select * from test

This result expected, since the table does not exist

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ can you share your minimal app

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

from sqlite.

eideard-hm avatar eideard-hm commented on June 12, 2024

Any solution, it does not work for me at all

from sqlite.

ileosebastian avatar ileosebastian commented on June 12, 2024

@rijeshpk thnks for this, @wimZ @ileosebastian Can you try what @rijeshpk proposed and tell me if it works. otherwise there is solution to clean the cache programmatically when you re-install the app

In fact @jepiqueau, I can say that what @rijeshpk says works perfectly for my case. That is, I applied everything mentioned in android-quirks (I didn't do it before because I was testing it only in a web environment with SQL queries) and then reinstalled all the packages and added android back to the ionic project to see if it worked. It is indeed an error in the cache and/or permissions that the application has that is causing the CapacitorSQLitePlugin to not be instantiated.

from sqlite.

ileosebastian avatar ileosebastian commented on June 12, 2024

import {CapacitorSQLite,SQLiteConnection) from '@capacitor-community/sqlite' const _db = CapacitorSQLite const dbName='abc'

//1 await _db.createConnection({database: dbName,encrypted: false,mode: 'no-encryption',version: 1,})

//2 await _db.open({ database: dbName })

//3 await _db.execute({database: dbName, statements: [DROP TABLE IF NOT EXIST test], values: [],}) Error: Execute: Attempt to invoke virtual method 'java.lang.String java.lang.String.replace(java.lang.CharSequence, java.lang.CharSequence)' on a null object reference at returnResult ((index):917:32) at cap.fromNative ((index):899:17) at :1:18

//4 await _db.query({database: dbName, statement: 'Select * from test', values: [], }) Error: Query: in selectSQL cursor no such table: test: , while compiling: Select * from test

This result expected, since the table does not exist

Following only the lines of code that execute the queries from the plugin (but uncommented), the 'test' table is never created in the first instance, so it is correct that the query cannot be made.

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ can you share it on github so i can clone it and test it

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

@jepiqueau

You should now have access

Appreciate your support!!!

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ can you give me the link

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ i mean the link to your github repository where you have updated your app so i can clone it quickly

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

my 1st time sharing.

https://github.com/wimZ/sqlitetest/invitations

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ i got it and i will have a look

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ Did the bug happens on Android as you do not implement the web part

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

Yes its android where it fails

My original app is only android.

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@wimZ modify your index.js file as below:

/** @format */

import { SplashScreen } from '@capacitor/splash-screen'
import {
   CapacitorSQLite,
   SQLiteConnection,
} from '@capacitor-community/sqlite'
const _sqlite = CapacitorSQLite
const sqliteConnection = new SQLiteConnection(_sqlite);
let _db
let dbName = 'abcdefghijk',
   result = false

const main = () => {
   SplashScreen.hide()
   document
      .querySelector('#connect-db')
      .addEventListener('click', async function (e) {
         try {
            console.log('creating connection')
            _db = await sqliteConnection.createConnection(
               dbName, false, 'no-encryption', 1, false)
            console.log("$$$$ _db: ",_db)
         } catch (e) {
            console.info(e.message)
         }
      })
   document
      .querySelector('#open-db')
      .addEventListener('click', async function (e) {
         try {
            console.info('opening db')
            await _db.open()
         } catch (e) {
            console.info(e.message)
         }
      })
   document
      .querySelector('#drop-db')
      .addEventListener('click', async function (e) {
         try {
            result = await _db.execute(`DROP TABLE IF EXISTS test;`)
            console.log(result)
         } catch (e) {
            console.info(e.message)
            console.log(e.stack)
         }
      })
   document
      .querySelector('#create-db')
      .addEventListener('click', async function (e) {
         try {
            result = await _db.execute(
               `CREATE TABLE IF NOT EXISTS test ('sleutel','naam')`)
            console.log(result)
         } catch (e) {
            console.info(e.message)
         }
      })
   document
      .querySelector('#insert-db')
      .addEventListener('click', async function (e) {
         try {
            result = await _db.execute(
                  `insert into test (sleutel, naam) VALUES (1, 'truus');`)
            console.log(result)
         } catch (e) {
            console.info(e.message)
         }
         try {
            result = await _db.execute('insert into test (sleutel, naam) VALUES (2, "kees");')
            console.log(result)
         } catch (e) {
            console.info(e.message)
         }
      })
   document
      .querySelector('#query-db')
      .addEventListener('click', async function (e) {
         try {
            result = await _db.query('Select * from test;',[])
            console.log(JSON.stringify(result.values))
            console.log(result)
         } catch (e) {
            console.info(e.message)
         }
      })
}

main()

this will work
i will advise you to look at the tutorials
Good luck for your development

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

Works! Thanks.

The app was migrated from Cordova, and as far as I recall I never modified the way I instantiated sqlite db

I'll check if problem in the app can be solved the same way.

from sqlite.

wimZ avatar wimZ commented on June 12, 2024

Tests so far show that my issue is resolved.

Thanks for supporting this.

from sqlite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.