Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install most recent version of Sqlite aar when using Room On Android

Im investigating Android Room databases in my current application.

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

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

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

or

Is this not possible?

The sqlite.org website has this

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.

  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 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') }

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

like image 312
Hector Avatar asked Dec 10 '20 14:12

Hector


People also ask

Where do I put AAR file in Android project?

Add your AAR or JAR as a dependency Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your . aar or .

Do I need to install SQLite for Android studio?

SQLite is part of the standard Android library; its classes can be found in android. database. sqlite. You don't need to install it.

What is the best way to Access SQLite in Android?

The androidx.sqlite library contains abstract interfaces along with basic implementations which can be used to build your own libraries that access SQLite. You might want to consider using the Room library, which provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite.

How to install SQLite3 on Windows?

The sqlite3 library is pre-installed in the standard library, but we will look into how to install it manually in different versions and using different packages. We will be using pip to install the SQLite package in this case. Type the below command in the cmd to install the SQLite package on your system.

What is the latest version of androidx SQLite?

androidx.sqlite:sqlite:2.2.0-alpha01, androidx.sqlite:sqlite-framework:2.2.0-alpha01, and androidx.sqlite:sqlite-ktx:2.2.0-alpha01 are released. Version 2.2.0-alpha01 contains these commits. Note: newer versions androidx libraries now correctly reflect implementation dependencies versus api dependencies.

Can I use room instead of a non-room SQLite implementation?

If your app currently uses a non-Room implementation of SQLite, read this page to learn how to migrate your app to use Room instead. If Room is the first SQLite implementation that you are using in your app, see Save data in a local database using Room for basic usage information.


2 Answers

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()

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.

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.

like image 200
CommonsWare Avatar answered Oct 19 '22 15:10

CommonsWare


SQLite comes bundled with the Android SDK, that means that SQLite version is changing with the increasing of the API level. Phone manufacturers can choose to ship different sqlite version with their device system.

Final verdict, you can't change it, unless running on rooted device.

Edit: Guide suggests using different sqlite version to by-pass the built-in, that would require usage of different wrapper around the new sqlite which will not communicate with the system one. This prevents you from using android database packages, including Room.

like image 44
Nikola Despotoski Avatar answered Oct 19 '22 16:10

Nikola Despotoski