I'm trying to use sqlitecipher library which requires using native libraries. Their tutorial is very simple but it doesn't work for me. Every time I get the following error:
我正在尝试使用需要使用本地库的sqlitecipher库。他们的教程很简单,但对我来说并不适用。每次我得到以下错误:
FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.example.test-2.apk,libraryPath=/data/app-lib/org.example.test-2]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:141)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:136)
it means .so files were not attached during compilation.
它的意思是,在编译过程中没有附加文件。
all 3 files are stored in /libs/armeabi/ directory.
所有3个文件都存储在/libs/armeabi/目录中。
I assumed that the problem is that I use maven to manage dependencies (building is performed using Android Studio anyways). The next try - include those libraries into maven dependencies. According documentation it is pretty easy. I couldn't find them in a public repository so I used <scope>system</scope>
with a tag. They were visible but it didn't work. Later found this link where it is said that scope "system" won't work, tried adding those libraries into local repository using
我假设问题是我使用maven来管理依赖关系(构建是使用Android Studio进行的)。下一个尝试——将这些库包含到maven依赖项中。根据文档,这很容易。我在公共存储库中找不到它们,所以我使用了
mvn install:install-file -DgroupId=net.sqlitecipher -DartifactId=stlport_shared -Dversion=1.0 -Dfile=libstlport_shared.so -Dpackaging=so -DgeneratePom=true
in the end - it didn't work.
最后,它没有起作用。
Also I saw this topic, probably this is a solution but I don't use gradle currently. Is there a way to include .so files into the apk without moving from maven to gradle?
我也看到了这个主题,也许这是一个解决方案,但我现在不使用gradle。是否有一种方法可以将文件包含到apk中,而不需要从maven转移到gradle?
As I understood Android Studio uses gradle internally to build apks, so all my efforts with maven are useless until they start supporting native libraries, am I right? I have also tried building the project with Intellij IDEA Cardea (13.0), unfortunately without any success.
正如我所理解的,Android Studio在内部使用gradle来构建apks,所以我在maven上的所有努力都是无用的,直到它们开始支持本地库,对吗?我还尝试用Intellij IDEA Cardea(13.0)构建这个项目,可惜没有成功。
3 个解决方案
#1
10
As soon as the native libs are in /libs/armeabi/ all you have to do is to configure the android plugin properly. Something like this:
一旦本机libs处于/libs/armeabi/您所要做的就是正确配置android插件。是这样的:
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
...
</configuration>
<extensions>true</extensions>
</plugin>
#2
1
To Question 1: Yes. I haven't had this specific problem before, but genearlly you don't need to swich to gradle. It is possible to use an ant task to add SO files to an APK. And since maven can run Ant tasks it possible.
问题1:是的。我以前还没有遇到过这个问题,但你不需要把这个问题弄清楚。可以使用ant任务将文件添加到APK中。因为maven可以运行Ant任务。
The nativeLibsToJar that you found here is nothing else than a task that puts all the SO files into a ZIP file and then uses the extension JAR instead of ZIP. You can easily do that with the Ant task Zip (and maybe additionally rename).
您在这里找到的nativeLibsToJar不过是一个任务,它将所有的SO文件放入ZIP文件中,然后使用扩展JAR而不是ZIP。您可以轻松地使用Ant任务Zip(或者另外重命名)来实现这一点。
To Question 2: No. Because of the first answer. There is no need for "maven to support native libraries". Just use Ant as build-system.
问题2:没有。因为第一个答案。不需要“maven来支持本地库”。只需要使用Ant作为构建系统。
#3
1
You have to create jni folder for .so file include in android project using android studio.
您必须创建jni文件夹。因此,在android项目中使用android studio的文件包括。
I have attached image please follow these steps.
我附上图片请按照以下步骤。
After creating jnilib folder you can put your all .so files in this folder.
创建jnilib文件夹后,可以将所有文件都放在该文件夹中。
#1
10
As soon as the native libs are in /libs/armeabi/ all you have to do is to configure the android plugin properly. Something like this:
一旦本机libs处于/libs/armeabi/您所要做的就是正确配置android插件。是这样的:
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
...
</configuration>
<extensions>true</extensions>
</plugin>
#2
1
To Question 1: Yes. I haven't had this specific problem before, but genearlly you don't need to swich to gradle. It is possible to use an ant task to add SO files to an APK. And since maven can run Ant tasks it possible.
问题1:是的。我以前还没有遇到过这个问题,但你不需要把这个问题弄清楚。可以使用ant任务将文件添加到APK中。因为maven可以运行Ant任务。
The nativeLibsToJar that you found here is nothing else than a task that puts all the SO files into a ZIP file and then uses the extension JAR instead of ZIP. You can easily do that with the Ant task Zip (and maybe additionally rename).
您在这里找到的nativeLibsToJar不过是一个任务,它将所有的SO文件放入ZIP文件中,然后使用扩展JAR而不是ZIP。您可以轻松地使用Ant任务Zip(或者另外重命名)来实现这一点。
To Question 2: No. Because of the first answer. There is no need for "maven to support native libraries". Just use Ant as build-system.
问题2:没有。因为第一个答案。不需要“maven来支持本地库”。只需要使用Ant作为构建系统。
#3
1
You have to create jni folder for .so file include in android project using android studio.
您必须创建jni文件夹。因此,在android项目中使用android studio的文件包括。
I have attached image please follow these steps.
我附上图片请按照以下步骤。
After creating jnilib folder you can put your all .so files in this folder.
创建jnilib文件夹后,可以将所有文件都放在该文件夹中。