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