将.so文件添加到Android项目
问题描述:
我正在尝试将SQLCipher添加到我的项目中。我能够将jar文件链接到项目,但链接提供的.so文件时出现问题。将.so文件添加到Android项目
由于我得到UnSatisfiedLinkError当我尝试打开数据库。
任何人都可以请让我知道最好的方式来添加.so文件到项目并让它运行。
答
除了jar文件,你需要包含.so文件。在我的项目中,我有:
jar files in project_root/libs/
.so files in project_root/libs/armeabi/
还要确保您已正确添加了.jar文件。转到Project Properties -> Java Build Path -> Libraries
标签确保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命令来验证哪些文件被部署到模拟器已经解包后。我看到过.so文件没有打包在.apk文件中的问题,这是由于IDE未指向您的应用程序的正确本机库路径。
可以让我知道你是如何将.so文件添加到项目中的...... –
你不会将.so文件添加到项目中。您只需将它们放在与jar文件相同的文件夹中名为'armeabi'的文件夹中即可。这些jar文件会在您从代码中调用'SQLiteDatabase.loadLibs'时自动加载这些.so文件。 – Caner
完成相同的许多时间,但我仍然gettingjava.lang.UnsatisfiedLinkError:dbopen –