📜 ⬆️ ⬇️

Compile SQLCipher for Android x86

SQLite, which is popular in the Android environment, allows SQLite 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, for example, you create a program for storing passwords and use SQLite, additional security measures will be very useful. 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 into your product. One of these solutions suitable for Android is SQLCipher. This is an open source SQLite extension that supports transparent 256-bit AES encryption of database files.
')
SQLCipher is used in a variety of commercial and open source 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 of SQLCipher made it one of the most widely used solutions for database encryption. In 2011, responding to numerous requests for support for SQLCipher on Android, Guardian Project and Zeletic released the appropriate version of the system. SQLCipher is available on many other platforms. In particular, these are Windows C / C ++, .NET, Ruby, Java, PHP, Python, QT, Mac OS X and Linux.

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

In general, to integrate SQLCipher support into an Android application, you first need to add the appropriate libraries to the project, and second, instead of using SQLite tools from android.database.sqlite.SQLiteDatabase, use similar ones, but from net.sqlcipher .database.SQLiteDatabase. Read more about it here .

Setting up a Linux environment


Before compiling SQLCipher for Android, you need to properly prepare a computer with installed Linux. In particular, 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 source code SQLCipher, we will do this with the following command:

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

After the repository is cloned into a local folder, you can begin the library building procedure.

Build the SQLCipher Library in Linux


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

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

In order to prepare the set of files required for a successful SQLCipher build, the make init may take some time. During preparation, the following external libraries will be loaded:


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

 ~/android-database-cipher> make 

Running this command will compile the libraries for the target architectures listed in the Application.mk file. 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 string:

 APP_ABI := x86 

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

Error messages at this stage usually indicate incorrect system settings. If the “android update project fails” error message appears during the execution of the make command, then, most likely, the system paths to Android tools are not added to the PATH variable. The following commands will help 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 absence in the PATH variable of the ndk-build location information. 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 get the target id , you can use the android list targets. command android list targets.

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

findings


We reviewed 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, SQLCipher will help securely protect the data to everyone who decides to use this library in their project.

Source: https://habr.com/ru/post/278493/


All Articles