向Android项目中添加.so文件

4

我正在尝试将SQLCipher添加到我的项目中。我已经成功地将jar文件链接到项目中,但在链接提供的.so文件时出现了问题。

由于这个问题,当我尝试打开数据库时,会出现UnSatisfiedLinkError错误。

请问有什么最佳方法可以将.so文件添加到项目中并使其正常运行吗?

2个回答

5
除了jar文件之外,您还需要包含.so文件。在我的项目中,我有:
jar files in project_root/libs/
.so files in project_root/libs/armeabi/

请确保您已正确添加了.jar文件。在项目属性 -> Java构建路径 -> 库选项卡中,确保已添加commonc-codec.jargueva-r09.jarsqlcipher.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”):

你不需要将 .so 文件添加到项目中,只需将它们放置在名为 armeabi 的文件夹中,与 jar 文件放在同一文件夹中。当你从代码中调用 SQLiteDatabase.loadLibs 时,这些 jar 文件会自动加载这些 .so 文件。 - Caner
已经做了很多次,但我仍然得到java.lang.UnsatisfiedLinkError: dbopen。 - Rahul Kalidindi
1
确保在调用getWritableDatabase之前调用SQLiteDatabase.loadLibs()。有关详细信息,请参见我的编辑。 - Caner

0

你可以使用adb shell命令来验证模拟器解压后部署了哪些文件。我曾经遇到过一个问题,即.apk文件中没有打包.so文件,这是因为IDE没有指向应用程序的正确本地库路径。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接