在 Android 上使用 Room 时如何安装最新版本的 Sqlite aar [英] How to install most recent version of Sqlite aar when using Room On Android

查看:44
本文介绍了在 Android 上使用 Room 时如何安装最新版本的 Sqlite aar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查我当前应用程序中的 Android Room 数据库.

Im investigating Android Room databases in my current application.

我正在尝试通过使用最新的 aar

I am trying to install the most recent version of Sqlite by employing the most recent aar

我尝试将 aar 放在我的数据库模块 libs 文件夹中并在我的 gradle 文件中引用它,但是显示的 sqlite 版本总是 3.22.0其中 aar3.34.0

I have tried placing the aar in my database module libs folder and referencing that in my gradle file however the sqlite version displayed is always 3.22.0 where the aar is 3.34.0

我需要遵循哪些步骤来覆盖默认提供的 Sqlite 版本并使用我下载的 aar 文件?

what are the steps I need to follow to override the version of Sqlite supplied by default and use my downloaded aar file?

这不可能吗?

sqlite.org 网站有这个

The sqlite.org website has this

可以通过三种方式将 SQLite Android 绑定添加到应用:

There are three ways to add the SQLite Android bindings to an application:

通过向 Android Studio 应用程序添加预构建的 aar 文件项目.通过构建 aar 文件,然后将其添加到应用程序中Android Studio 项目如 (1) 中所示.通过添加 SQLite Android将源代码绑定到其他代码并将其与其他代码一起构建应用程序代码.默认情况下,SQLite Android 绑定支持Android API 级别 16 及更高级别(Android 4.1 及更高版本).那里也是一个单独的版本,支持 Android API 级别 9 和更大(Android 2.3 及更高版本).请注意额外的步骤如果您希望使用该版本,则参与获取代码与 API 级别 9 兼容.

By adding a pre-built aar file to the applications Android Studio project. By building an aar file, then adding it to the applications Android Studio project as in (1). By adding the SQLite Android bindings source code to and building it along with the other application code. By default, the SQLite Android bindings support Android API levels 16 and greater (Android versions 4.1 and up). There is also a separate version that supports Android API levels 9 and greater (Android version 2.3 and up). Please note the extra step involved in obtaining the code if you wish to use the version compatible with API level 9.

  1. 使用预构建的 aar 文件 这是最直接的选项.一个aar"文件类似于 jar 文件,除了它可能包含编译的java类和本机代码.最新的aar文件可用于 API 级别 16 及更高级别的 SQLite 版本可从这里获得页面.

将aar文件添加到Android有两个步骤工作室项目:

There are two steps involved in adding an aar file to an Android Studio project:

导入模块.在 Android Studio 2.1 中,这是通过选择文件"->新"->新模块……"菜单然后选择导入 JAR/AAR 包".添加对新模块的依赖到主应用程序模块(或所有将使用SQLite Android 绑定).在 Android Studio 2.1 中,依赖项可能是使用项目结构对话框创建(选择文件"->项目结构...") 或通过将类似于以下的代码添加到应用程序模块 build.gradle 文件:依赖{//更改sqlite-android-3130000";到新模块的名称!编译项目(':sqlite-android-3130000')}

Import the module. In Android Studio 2.1 this is accomplished by selecting the "File" -> "New" -> "New Module..." menu and then choosing "Import JAR/AAR Package". Add a dependency on the new module to the main application module (or to all modules that will use the SQLite Android bindings). In Android Studio 2.1 the dependency may be created using the project structure dialog (select "File" -> "Project Structure...") or by adding code similar to the following to the application modules build.gradle file: dependencies { // Change "sqlite-android-3130000" to the name of the new module! compile project(':sqlite-android-3130000') }

我已经尝试过这种方法,room 仍然报告原始版本.我相信有一种方法可以替换 Android 默认提供的捆绑 sqlite

I've tried this approach and room still reports the original version. I believe there is an approach that will replace the bundled sqlite that is provided by Android as default

推荐答案

要在 Room 中使用不同的数据库实现,您需要找到(或创建)一个 SupportSQLiteOpenHelper.Factory 实现并将其提供给你的 RoomDatabase.Builder 通过openHelperFactory():

To use a different database implementation with Room, you need to find (or create) a SupportSQLiteOpenHelper.Factory implementation and supply it to your RoomDatabase.Builder via openHelperFactory():

val builder = Room.databaseBuilder(context, SomeDatabase.class, DB_NAME)
  .openHelperFactory(factory)
  .build()

最简单的方法是使用 Requery 的独立 SQLite 库.您将使用 RequerySQLiteOpenHelperFactory 作为 SupportSQLiteOpenHelper.Factory 的实现,它将使用 Requery 的 SQLite 打包副本而不是框架副本.

The simplest way to do that is to use Requery's standalone SQLite library. You would use RequerySQLiteOpenHelperFactory as the implementation of the SupportSQLiteOpenHelper.Factory, and it will use Requery's packaged copy of SQLite instead of the framework one.

如果出于某种原因,您不想使用 Requery 的库,您需要找到您喜欢的等效库,或者您需要自己实现 SupportSQLite* API.我为 Android 的 SQLCipher 做了两次,虽然很痛苦,但肯定是可行的.

If, for some reason, you do not wish to use Requery's library, you would need to find an equivalent that you like, or you would need to implement the SupportSQLite* APIs yourself. I did that twice for SQLCipher for Android, and it is a pain, but it certainly is doable.

这篇关于在 Android 上使用 Room 时如何安装最新版本的 Sqlite aar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆