将 SQLCipher 最新版本 v4.5.4 与 android kotlin 项目集成

问题描述 投票:0回答:1

我可以找到很多旧版本的 SQLCipher 与 android 的集成示例,它也可以工作。但我需要集成最新版本的 SQLCipher,如 v4.5.4,因为它提到它有更多的性能优化。谁能帮我解决这个问题?

我尝试了 SQLCipher 最新文档中给出的步骤,但我无法遵循该步骤,因为它不清楚并且需要我不知道如何获取的数据库文件路径。

kotlin android-sqlite android-room sqlcipher sqlcipher-android
1个回答
0
投票

我知道了

        System.loadLibrary("sqlcipher")
        val factory = SupportOpenHelperFactory(encryptionKey)
        // if the INSTANCE is not null, then return it,
        // if it is, then create the database
        return INSTANCE ?: synchronized(this) {
            val instance = Room.databaseBuilder(
                context.applicationContext,
                MYDatabase::class.java,
                DATABASE_NAME
            )
                .openHelperFactory(factory)
                .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5)
                .build()
            INSTANCE = instance
            // return instance
            instance
        }

这里应该在任何数据库操作发生之前调用 System.loadLibrary("sqlcipher")

© www.soinside.com 2019 - 2024. All rights reserved.