sqlcipher是sqlite的加版本,分为免费版和收费版。
这里研究的是开源的免费版
https://github.com/sqlcipher/sqlcipher
Android码源默认提供了sqlite的native,jni和java版本,但没有提供sqlcipher,开发用到需要自己添加。
sqlcipher需要配置openssl,写一个android.bp
cpp
android_sqlite_cflags = [
"-DHAVE_USLEEP=1",
"-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576",
"-DSQLITE_THREADSAFE=1",
"-DNDEBUG=1",
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1",
"-DSQLITE_TEMP_STORE=3",
"-DSQLITE_ENABLE_FTS3_BACKWARDS",
"-DSQLITE_ENABLE_LOAD_EXTENSION",
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT",
"-DSQLITE_ENABLE_COLUMN_METADATA",
"-DSQLITE_ENABLE_FTS4",
"-DSQLITE_ENABLE_UNLOCK_NOTIFY",
"-DSQLITE_ENABLE_RTREE",
"-DSQLITE_SOUNDEX",
"-DSQLITE_ENABLE_STAT3",
"-DSQLITE_ENABLE_FTS4_UNICODE61",
"-DSQLITE_THREADSAFE",
"-Wno-unused-parameter",
"-Wno-pointer-arith",
"-Wno-unused-variable"
]
sqlcipher_cflags = [
"-DSQLITE_HAS_CODEC",
"-DHAVE_FDATASYNC=0",
"-Dfdatasync=fsync",
]
sqlcipher_files = ["src/sqlite3.c"]
//APP_STL := c++_shared
//APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
//APP_PLATFORM := android-26
// ANDROIDMK TRANSLATION ERROR: unsupported assignment to LOCAL_EXPORT_C_INCLUDES
// LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/
//LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/arm64-v8a/libcrypto.so
// ANDROIDMK TRANSLATION ERROR: unsupported include
// include $(PREBUILT_SHARED_LIBRARY)
cc_prebuilt_library_shared {
name: "libcrypto2",
target: {
android_arm: {
srcs: ["lib/armeabi-v7a/libcrypto.so"],
},
android_arm64: {
srcs: ["lib/arm64-v8a/libcrypto.so"],
},
},
strip: {
none:true,
},
//shared_libs: ["libx", "libxx", "libxxx", "libxxxx"],
check_elf_files: false,
compile_multilib: "both"//32位和64位都预编译
}
cc_library_shared {
name: "sqlite3_ext2",
host_ldlibs: ["-llog"],
srcs: sqlcipher_files,
local_include_dirs: [
"src",
"include",
],
cflags: android_sqlite_cflags + sqlcipher_cflags,
//LOCAL_STATIC_LIBRARIES := static-libcrypto
shared_libs: ["libcrypto2", "liblog",],
}
详细使用看:
GitHub - blogercn/android_sqlciphe: android natvity C/C++使用的加密数据库sqlciphe
可以用于ndk,可以复制到android源码供C++层开发使用