Back to Home

Compiling SQLCipher for Android x86 / Intel Blog

SQL · SQLite · SQLCipher · Android

Compiling SQLCipher for Android x86

Original author: Praveen Kundurthy
  • Transfer
SQLite, popular in the Android environment, allows you to organize convenient data storages; its capabilities are sufficient for many applications, but not for those that work with information that needs to be protected.



If your project in this series, say, you create a program for storing passwords and use SQLite, additional security measures will be very helpful. One such measure is encryption.

The best that almost any developer can do when it comes to encryption is to find a ready-made, time-tested, widely used solution and implement it in their product. One such solution suitable for Android is SQLCipher. This is an open source extension for SQLite that supports transparent 256-bit AES encryption of database files.

SQLCipher is used in many commercial open source development and products. In fact, it is one of the most popular database encryption systems for mobile, embedded, and desktop platforms.

SQLCipher was released by Zeletic in 2008 and was initially used in the company's own developments, in particular, in the Strip password manager. Later, reliability, low system load and small size SQLCipher made it one of the most widely used database encryption solutions. In 2011, responding to numerous requests for SQLCipher support on Android, the Guardian Project and Zeletic released the corresponding version of the system. SQLCipher is also available on many other platforms. In particular, these are Windows C / C ++, .NET, Ruby, Java, PHP, Python, QT, Mac OS X and Linux.

We’ll talk about how to compile SQLCipher for Android devices built on the Intel x86 platform using a Linux-installed computer as a working machine.

In general, to integrate SQLCipher support into an Android application, you must firstly add the appropriate libraries to the project, and secondly, instead of using SQLite tools from android.database.sqlite.SQLiteDatabase, use similar ones, but from net.sqlcipher .database.SQLiteDatabase. Learn more about this here .

Setting up a Linux environment


Before you compile SQLCipher for Android, you need to properly prepare your computer with Linux installed. In particular, you need to download and install the following:

  1. Android SDK
  2. Adnroid ndk
  3. Java Development Kit (JDK)

On the Zeletic website you can find different options for downloading the SQLCipher source code, we will do this with the following command:

git clone https://github.com/sqlcipher/android-database-sqlcipher.git

After the repository is cloned to a local folder, you can start the library build procedure.

Building the SQLCipher library on Linux


Suppose the source code of the library is in a folder /home/test/android-database-cipher/. Run the following commands:

Cd /home/test/android-database-cipher/
~/android-database-cipher> make init

In order to prepare the set of files necessary for the successful assembly of SQLCipher, the team make initmay take some time. In preparation, the following external libraries will be loaded:

  • external / sqlcipher
  • external / android-sqlite
  • external / dalvik
  • external / icu4c
  • external / openssl
  • external / platform-frameworks-base

After initialization is complete, run the following command to start compilation:

~/android-database-cipher> make

Running this command will compile libraries for the target architectures listed in the file Application.mk. In our case, this file is located at /home/test/android-database-cipher/jni/Application.mk. In order to get the version of the library compiled for the x86 platform, it must contain the following line:

APP_ABI := x86

Upon successful compilation, what we need will be in the libs/x86.

Error messages folder at this stage usually indicate incorrect system settings. If makean error message of the form “android update project fails” appears during the execution of the command , then most likely the path to the Android tools in the system is not added to the PATH variable. The following commands will help to fix this:

export PATH=$PATH:~/android-sdk-linux/tools
export PATH=$PATH:~/ android-sdk-linux/platform-tools

The “ndk-build: command not found” error is caused by the lack of ndk-build location information in the PATH variable. It can be fixed like this:

export PATH=$PATH:~/ android-ndk-linux /android-ndk-r10d

If you encounter the error message “build.xml not found”, you can automatically generate build.xml like this:

~/sqlcipher/android-database-sqlcipher> cd .. 
~/sqlcipher> android update project --target 1 --path ./ --subprojects

In order to obtain target id, you can use the command android list targets.

After the problems are fixed, run the compilation again by going to the directory with the SQLCipher source code.

conclusions


We examined here the process of preparing SQLCipher for Android devices built on the Intel x86 platform using a working Linux machine. If you are running Windows, here you can find information about building SQLCipher on Windows systems. We hope that SQLCipher will help reliably protect data for everyone who decides to use this library in their project.

Read Next