Skip to content

fix(android): migrate from android-database-sqlcipher to sqlcipher-android - #607

Merged
robingenz merged 5 commits into
capacitor-community:masterfrom
dragermrb:fix-16kb-pagesize
Jul 2, 2025
Merged

fix(android): migrate from android-database-sqlcipher to sqlcipher-android#607
robingenz merged 5 commits into
capacitor-community:masterfrom
dragermrb:fix-16kb-pagesize

Conversation

@dragermrb

Copy link
Copy Markdown
Contributor

Pull request to migrate from net.zetetic:android-database-sqlcipher to net.zetetic:sqlcipher-android
to allow using an Android 15 (API Level 35) with 16 KB page size supports.

Related issue: #594

@DGeoWils

Copy link
Copy Markdown

@robingenz Can we get this merged?

@robingenz

Copy link
Copy Markdown
Member

Unfortunately, I don't have the capacity to test it at the moment. So this PR will have to wait or someone else from the Capacitor community takes over.

@DGeoWils

Copy link
Copy Markdown

Thank you!

@shiv19

shiv19 commented May 17, 2025

Copy link
Copy Markdown

I tried these change on this version of the plugin
"@capacitor-community/sqlite": "6.0.1",

And the changes seem to be working fine when deployed on a 16kb page size device.
However, I did not perform extensive testing.
I'll report back if it passes QA and we end up shipping this to prod.

Without the changes in this PR, the app does crash on launch on a 16kb page size device.
cc @robingenz

If merged, we also need to patch this on the 6.x version of the plugin for capacitor 6 users.

@shiv19
shiv19 requested a review from Copilot May 18, 2025 22:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Migrate from net.zetetic:android-database-sqlcipher to net.zetetic:sqlcipher-android to support Android 15's 16 KB page size.

  • Swapped imports, casts, and method calls to use net.zetetic.database.sqlcipher types and overloads.
  • Replaced SQLiteDatabase.loadLibs(context) with System.loadLibrary("sqlcipher") and updated openDatabase and openOrCreateDatabase signatures.
  • Changed conversion of passwords to bytes and updated exception handling in changePassword.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
UtilsSQLite.java Replaced net.sqlcipher.Cursor with SQLiteCursor and adjusted casts.
UtilsSQLCipher.java Swapped native library loading, updated database open calls with new overloads, and tweaked exception.
UtilsDrop.java Updated imports and casts to use SQLiteCursor for table/view/index/trigger queries.
Database.java Swapped library init, adjusted password byte conversion, open/creation calls, and cursor usage.
Files not reviewed (1)
  • android/build.gradle: Language not supported
Comments suppressed due to low confidence (3)

android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java:207

  • [nitpick] The parameter name nwpassword is unclear; rename it to newPassword for readability and consistency.
public void changePassword(Context ctxt, File file, String password, String nwpassword) throws Exception {

android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java:214

  • Throwing a generic Exception loses error specificity; consider using SQLiteException or a custom exception type to preserve context.
throw new Exception("database " + file.getAbsolutePath() + " open failed");

android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java:117

  • Calling System.loadLibrary directly may miss other native dependencies; verify that all required native libraries are loaded or use the library’s recommended initialization method.
System.loadLibrary("sqlcipher");

try {
if (globVar.secret.length() > 0) {
db = SQLiteDatabase.openDatabase(dbPath.getAbsolutePath(), globVar.secret, null, SQLiteDatabase.OPEN_READONLY);
db =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linting error might be coming from this section of UtilsSQLCipher.java
Once the linting error is fixed, I can approve and merge this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

This PR is for @capacitor-community/sqlite@6.0.2 and linter works.

npm run prettier -- --check

> @capacitor-community/sqlite@6.0.2 prettier
> prettier "**/*.{css,html,ts,js,java}" --check

Checking formatting...
[warn] jsxBracketSameLine is deprecated.
All matched files use Prettier code style!

Error on CI tries to use version 7.x (I don't know why)

Run npm run lint

> @capacitor-community/sqlite@[7](https://github.com/capacitor-community/sqlite/actions/runs/15118907452/job/42548687676?pr=607#step:5:8).0.0 lint
> npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint


> @capacitor-community/sqlite@7.0.0 eslint
> eslint . --ext ts


> @capacitor-community/sqlite@7.0.0 prettier
> prettier "**/*.{css,html,ts,js,java}" --plugin=prettier-plugin-java --check

Checking formatting...
[warn] android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java
[warn] Code style issues found in the above file. Run Prettier with --write to fix.
Error: Process completed with exit code 1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a 6.x branch in the repo, you'll need to make the 6.x PR to that branch.

@robingenz

Copy link
Copy Markdown
Member

@shiv19 Thank you for helping out!

However, I did not perform extensive testing.

Please do that and let me know how it goes. Then we can merge it. This change is pretty central. So I want to be sure.

If merged, we also need to patch this on the 6.x version of the plugin for capacitor 6 users.

I always publish updates only for the latest Capacitor version supported to keep the maintenance effort as low as possible. Otherwise we would also have to test both versions intensively.

@dragermrb

Copy link
Copy Markdown
Contributor Author

@robingenz

I always publish updates only for the latest Capacitor version supported to keep the maintenance effort as low as possible. Otherwise we would also have to test both versions intensively.

Should I update the PR to version 7 of the plugin?

@robingenz

Copy link
Copy Markdown
Member

@dragermrb Isn't it already Capacitor 7? Your PR goes against the master branch. What do you need to change?

@dragermrb

Copy link
Copy Markdown
Contributor Author

I created the PR for version 6.0.2 (master branch at the time). Therefore, the fork used to develop the PR is based on version 6.0.2 and does not include the changes introduced in version 7.x.

Linter, for example, differs between versions 6 and 7.

@robingenz

Copy link
Copy Markdown
Member

@dragermrb So yes, please update to Capacitor 7.

@dragermrb

Copy link
Copy Markdown
Contributor Author

@dragermrb So yes, please update to Capacitor 7.

Fixed

@robingenz

Copy link
Copy Markdown
Member

Here is a dev release for testing:

npm i @capacitor-community/sqlite@7.0.0-dev.bf54d28.1747847115

If no bugs are reported in the next few days, I'll merge it.

@robingenz robingenz changed the title (android) Migrate from android-database-sqlcipher to sqlcipher-android fix(android): migrate from android-database-sqlcipher to sqlcipher-android May 21, 2025
@shiv19

shiv19 commented May 21, 2025

Copy link
Copy Markdown

@robingenz, we've shipped this fix to prod (minus the last commit with the UTF-8 encoding param). Our QA didn't find any issues, and it also passed the google app review. We're monitoring crash analytics closely. If you don't hear back from me here, it means it's all good ✅️.

@davinderclerisy

Copy link
Copy Markdown

@robingenz Just checking in - any updates on when this fix will be released?

@robingenz
robingenz merged commit 43c689b into capacitor-community:master Jul 2, 2025
@MonicaExplan

Copy link
Copy Markdown

I tried these change on this version of the plugin "@capacitor-community/sqlite": "6.0.1",

And the changes seem to be working fine when deployed on a 16kb page size device. However, I did not perform extensive testing. I'll report back if it passes QA and we end up shipping this to prod.

Without the changes in this PR, the app does crash on launch on a 16kb page size device. cc @robingenz

If merged, we also need to patch this on the 6.x version of the plugin for capacitor 6 users.

Hello

I need to install this patch on my "@capacitor-community/sqlite": "6.0.1",

I try npm i @capacitor-community/sqlite@6.0.1#pull/607 but fails.
How can I install?

Thanks

@robingenz

Copy link
Copy Markdown
Member

@dragermrb Multiple users reported this issue that occurred as a result of this change. Can you take a look at it?

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants