使用 Room On Android 时如何安装最新版本的 Sqlite aar
How to install most recent version of Sqlite aar when using Room On Android
我正在调查 Android 当前应用程序中的房间数据库。
我正在尝试使用最新的 aar
安装最新版本的 Sqlite
我试过将 aar
放在我的数据库模块 libs
文件夹中并在我的 gradle 文件中引用它,但是显示的 sqlite 版本始终是 3.22.0
其中 aar
是 3.34.0
要覆盖默认提供的 Sqlite 版本并使用我下载的 aar 文件,我需要遵循哪些步骤?
或
这不可能吗?
sqlite.org 网站有这个
There are three ways to add the SQLite Android bindings to an
application:
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.
- 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 contain
both compiled java classes and native code. An aar file for the latest
SQLite release usable with API levels 16 and up is available from this
page.
There are two steps involved in adding an aar file to an Android
Studio project:
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
SQLite 与 Android SDK 捆绑在一起,这意味着 SQLite 版本随着 API 级别的增加而变化。 Phone 制造商可以选择在他们的设备系统中发布不同的 sqlite 版本。
最终判决,您无法更改它,除非 运行 在 root 设备上。
编辑:Guide 建议使用不同的 sqlite 版本来绕过内置的,这将需要在新的 sqlite 周围使用不同的包装器,它不会与系统通信。这会阻止您使用 android 数据库包,包括 Room。
要在 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
的实现,它将使用 SQLite 的 Requery 打包副本而不是框架副本。
如果出于某种原因,您不想使用 Requery 的库,则需要找到您喜欢的等效库,或者您需要自己实现 SupportSQLite*
API。我为 Android 的 SQLCipher 做了两次,这很痛苦,但它肯定是可行的。
在调查 android 项目中的数据持久性技术时,应考虑 android 的 JPA。 JPA 是 java 标准,JPA 代码可以在 java 服务器端或其他 java 客户端上重复使用。 android.
参见 Cmobilecom-JPA
我正在调查 Android 当前应用程序中的房间数据库。
我正在尝试使用最新的 aar
我试过将 aar
放在我的数据库模块 libs
文件夹中并在我的 gradle 文件中引用它,但是显示的 sqlite 版本始终是 3.22.0
其中 aar
是 3.34.0
要覆盖默认提供的 Sqlite 版本并使用我下载的 aar 文件,我需要遵循哪些步骤?
或
这不可能吗?
sqlite.org 网站有这个
There are three ways to add the SQLite Android bindings to an application:
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.
- 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 contain both compiled java classes and native code. An aar file for the latest SQLite release usable with API levels 16 and up is available from this page.
There are two steps involved in adding an aar file to an Android Studio project:
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
SQLite 与 Android SDK 捆绑在一起,这意味着 SQLite 版本随着 API 级别的增加而变化。 Phone 制造商可以选择在他们的设备系统中发布不同的 sqlite 版本。
最终判决,您无法更改它,除非 运行 在 root 设备上。
编辑:Guide 建议使用不同的 sqlite 版本来绕过内置的,这将需要在新的 sqlite 周围使用不同的包装器,它不会与系统通信。这会阻止您使用 android 数据库包,包括 Room。
要在 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
的实现,它将使用 SQLite 的 Requery 打包副本而不是框架副本。
如果出于某种原因,您不想使用 Requery 的库,则需要找到您喜欢的等效库,或者您需要自己实现 SupportSQLite*
API。我为 Android 的 SQLCipher 做了两次,这很痛苦,但它肯定是可行的。
在调查 android 项目中的数据持久性技术时,应考虑 android 的 JPA。 JPA 是 java 标准,JPA 代码可以在 java 服务器端或其他 java 客户端上重复使用。 android.
参见 Cmobilecom-JPA