DBFlow
5.0.0-alpha1
5.0.0-alpha1
  • README
  • Usage Docs
    • Including In Project
    • Getting Started
    • Proguard
    • Advanced Usage
      • Caching
      • List Queries
      • Multiple Modules
      • QueryModels
      • Indexing
      • SQLCipher
    • Main Usage
      • Databases
      • Models
      • Migrations
      • Views
      • Relationships
      • Storing Data
      • Retrieval
      • SQLite Query Language
      • TypeConverters
      • Observability
    • RXJavaSupport
    • ContentProviderGeneration
    • 5.0 Migration Guide
    • Migration4Guide
  • ISSUE_TEMPLATE
Powered by GitBook
On this page

Was this helpful?

  1. Usage Docs
  2. Advanced Usage

SQLCipher

PreviousIndexingNextMain Usage

Last updated 4 years ago

Was this helpful?

As of 3.0.0-beta2+, DBFlow now supports fairly easily.

To add the library add the library to your build.gradle with same version you are using with the rest of the library.

dependencies {
  implementation "com.dbflow5:sqlcipher:${version}"
  implementation "net.zetetic:android-database-sqlcipher:${sqlcipher_version}"
}

You also need to add the Proguard rule:

-keep class net.sqlcipher.** { *; }
-dontwarn net.sqlcipher.**

Next, you need to subclass the provided SQLCipherOpenHelper (taken from test files):

class SQLCipherOpenHelperImpl(context: Context,
                              databaseDefinition: DBFlowDatabase,
                              callback: DatabaseCallback?)
    : SQLCipherOpenHelper(context, databaseDefinition, callback) {
    override val cipherSecret get() = "dbflow-rules"
}

Note: that the constructor with DatabaseDefinition and DatabaseHelperListener is required.

Then in your application class when initializing DBFlow:

FlowManager.init(FlowConfig.Builder(context)
  .database(
      DatabaseConfig.Builder(CipherDatabase::class) { db, callback -> SQLCipherHelperImpl(context, databaseDefinition, callback))
      .build())
  .build())

And that's it. You're all set to start using SQLCipher!

SQLCipher