Using Sqlcipher under Android Studio

Source: Internet
Author: User

Android Studio and Eclipse are a little bit different.
Android Studio Version 1.3
SqlCipher version 3.3.1
1. Copy the Sqlcipher.jar to the project folder Libs;
2. Under Project Main, create a new two folder Jnilibs and assets, copy the Amreabi folder to Jnilibs, and copy icudt46l.zip to assets;
The structure diagram is as follows:

3. Load the class

    @Override    protectedvoidonCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        ButterKnife.bind(this);        SQLiteDatabase.loadLibs(this);  //在使用该类之前加载,而且只加载一次    }

Note The imported package is: import net.sqlcipher.database.SQLiteDatabase;

4. Details to note when creating a database
This method cannot open the database

      database = SQLiteDatabase.openOrCreateDatabase("data", "123456", null);        if (database != null) {            database.execSQL("CREATE TABLE IF NOT EXISTS person_student(name VARCHAR(20) NOT NULL , age INT(3))");        }

That's what you can

    File file = context.getDatabasePath("data");        file.mkdirs();        database = SQLiteDatabase.openOrCreateDatabase(file, "123456", null); //        if (database != null) {            database.execSQL("CREATE TABLE IF NOT EXISTS person_student(name VARCHAR(20) NOT NULL , age INT(3))");        }

Compare the two methods and manually create the folders in one more step.

The use of the same method is basically the same, its encryption and decryption are done internally, and we write the program basically does not matter, the main role is to prevent others through root access to the plaintext database directly.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Using Sqlcipher under Android Studio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.