gpt4 book ai didi

android - 在 Android 上使用 Room 时如何安装最新版本的 Sqlite aar

转载 作者:行者123 更新时间:2023-12-03 13:56:11 24 4
gpt4 key购买 nike

我正在调查我当前应用程序中的 Android Room 数据库。
我正在尝试使用最新的 aar 安装最新版本的 Sqlite
我试过放置 aar在我的数据库模块libs文件夹并在我的 gradle 文件中引用它,但是显示的 sqlite 版本始终是 3.22.0aar3.34.0我需要遵循哪些步骤来覆盖默认提供的 Sqlite 版本并使用我下载的 aar 文件?
或者
这不可能吗?
sqlite.org 网站有这个

There are three ways to add the SQLite Android bindings to anapplication:

By adding a pre-built aar file to the applications Android Studioproject. By building an aar file, then adding it to the applicationsAndroid Studio project as in (1). By adding the SQLite Androidbindings source code to and building it along with the otherapplication code. By default, the SQLite Android bindings supportAndroid API levels 16 and greater (Android versions 4.1 and up). Thereis also a separate version that supports Android API levels 9 andgreater (Android version 2.3 and up). Please note the extra stepinvolved in obtaining the code if you wish to use the versioncompatible with API level 9.

  1. Using a Pre-Built aar File This is the most straightforward option. An "aar" file is similar to a jar file, except that it may containboth compiled java classes and native code. An aar file for the latestSQLite release usable with API levels 16 and up is available from thispage.

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

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


我已经尝试过这种方法,房间仍然报告原始版本。
我相信有一种方法可以替代 Android 默认提供的 bundle sqlite

最佳答案

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

val builder = Room.databaseBuilder(context, SomeDatabase.class, DB_NAME)
.openHelperFactory(factory)
.build()
最简单的方法是使用 Requery's standalone SQLite library .您将使用 RequerySQLiteOpenHelperFactory作为 SupportSQLiteOpenHelper.Factory 的实现,它将使用 Requery 的 SQLite 打包副本而不是框架之一。
如果出于某种原因,您不想使用 Requery 的库,您需要找到一个您喜欢的等价物,或者您需要实现 SupportSQLite* API 自己。我为 Android 的 SQLCipher 做了两次,这很痛苦,但它肯定是可行的。

关于android - 在 Android 上使用 Room 时如何安装最新版本的 Sqlite aar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65236968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com