|
| 1 | +# SQLCipher for Android |
| 2 | + |
| 3 | +SQLCipher for Android provides a library replacement for `android.database.sqlite` on the Android platform for use on [SQLCipher](https://github.com/sqlcipher/sqlcipher) databases. This library is based on the upstream Android Bindings project and aims to be a long-term replacement for the original [SQLCipher for Android](https://github.com/sqlcipher/android-database-sqlcipher) library. |
| 4 | + |
| 5 | +### Compatibility |
| 6 | + |
| 7 | +SQLCipher for Android supports Android API 16 and up on `armeabi-v7a`, `x86`, `x86_64`, and `arm64_v8a` architectures. |
| 8 | + |
| 9 | +### Contributions |
| 10 | + |
| 11 | +We welcome contributions, to contribute to SQLCipher for Android, a [contributor agreement](https://www.zetetic.net/contributions/) needs to be submitted. All submissions should be based on the `master` branch. |
| 12 | + |
| 13 | + |
| 14 | +### Application Integration |
| 15 | + |
| 16 | +When available on Maven Central, add a reference to the library and dependency: |
| 17 | + |
| 18 | +``` |
| 19 | +implementation "net.zetetic:sqlcipher-android:<%=libraryVersion%>" |
| 20 | +implementation "androidx.sqlite:sqlite:<%=androidXSQLiteVersion%>" |
| 21 | +``` |
| 22 | + |
| 23 | +``` |
| 24 | +import net.zetetic.database.sqlcipher.SQLiteDatabase; |
| 25 | + |
| 26 | +System.loadLibrary("sqlcipher"); |
| 27 | +SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, password, null, null, null); |
| 28 | +``` |
| 29 | + |
| 30 | +### Pre/Post Key Operations |
| 31 | + |
| 32 | +To perform operations on the database instance immediately before or after the keying operation is performed, provide a `SQLiteDatabaseHook` instance when creating your database connection: |
| 33 | + |
| 34 | +``` |
| 35 | +SQLiteDatabaseHook hook = new SQLiteDatabaseHook() { |
| 36 | + public void preKey(SQLiteConnection connection) { } |
| 37 | + public void postKey(SQLiteConnection connection) { } |
| 38 | + }; |
| 39 | +``` |
| 40 | + |
| 41 | +### Building |
| 42 | + |
| 43 | +This repository is not batteries-included. Specificially, you will need to build `libcrypto.a`, the static library from OpenSSL using the NDK for the [supported platforms](#compatibility), and bundle the top-level `include` folder from OpenSSL. Additionally, you will need to build a SQLCipher amalgamation. These files will need to be placed in the following locations: |
| 44 | + |
| 45 | +``` |
| 46 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/android-libs/armeabi-v7a/libcrypto.a |
| 47 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/android-libs/x86/libcrypto.a |
| 48 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/android-libs/x86_64/libcrypto.a |
| 49 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/android-libs/arm64_v8a/libcrypto.a |
| 50 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/android-libs/include/ |
| 51 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/sqlite3.c |
| 52 | +<project-root>/sqlcipher/src/main/jni/sqlcipher/sqlite3.h |
| 53 | +``` |
| 54 | + |
| 55 | +To build the AAR package, either build directly within Android Studio, or from the command line: |
| 56 | + |
| 57 | +``` |
| 58 | +./gradlew assembleRelease |
| 59 | +``` |
| 60 | + |
0 commit comments