sqlcipher android支持mip和x86架构吗

2025-04-27 22:22:51
推荐回答(1个)
回答1:

1.将sqlcipher.jar复制到工程文件夹libs中;
2.在工程main下,新建两个文件夹jniLibs和assets,将amreabi文件夹整个复制到jniLibs中,将icudt46l.zip复制到assets中;
3.加载该类
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); SQLiteDatabase.loadLibs(this); //在使用该类之前加载,而且只加载一次 }

注意导入的包为:import net.sqlcipher.database.SQLiteDatabase;
4.创建数据库的时候注意的细节
此方法无法打开数据库
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))"); }

这种才可以
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))"); }

比较两种方法,多了一步手动创建文件夹。
使用方法基本相同,它的加密解密都在内部完成,和我们写程序基本没关系,主要作用是防止别人通过root权限直接查看明文数据库。