我正在尝试将SQLCipher添加到我的项目中。我已经成功地将jar文件链接到项目中,但在链接提供的.so文件时出现了问题。
由于这个问题,当我尝试打开数据库时,会出现UnSatisfiedLinkError错误。
请问有什么最佳方法可以将.so文件添加到项目中并使其正常运行吗?
jar files in project_root/libs/
.so files in project_root/libs/armeabi/
项目属性 -> Java构建路径 -> 库
选项卡中,确保已添加commonc-codec.jar
、gueva-r09.jar
和sqlcipher.jar
。1) Add a single sqlcipher.jar and a few .so’s to the application libs directory
2) Update the import path from android.database.sqlite.* to info.guardianproject.database.sqlite.* in any source files that reference it. The original android.database.Cursor can still be used unchanged.
3) Init the database in onCreate() and pass a variable argument to the open database method with a password*:
SQLiteDatabase.loadLibs(this); //first init the db libraries with the context
SQLiteOpenHelper.getWritableDatabase(“thisismysecret”):
你可以使用adb shell命令来验证模拟器解压后部署了哪些文件。我曾经遇到过一个问题,即.apk文件中没有打包.so文件,这是因为IDE没有指向应用程序的正确本地库路径。
armeabi
的文件夹中,与 jar 文件放在同一文件夹中。当你从代码中调用SQLiteDatabase.loadLibs
时,这些 jar 文件会自动加载这些 .so 文件。 - CanergetWritableDatabase
之前调用SQLiteDatabase.loadLibs()
。有关详细信息,请参见我的编辑。 - Caner