简体   繁体   English

本机库(.so文件)不会添加到android项目中

[英]Native libraries (.so files) are not added to an android project

I'm trying to use sqlitecipher library which requires using native libraries. 我正在尝试使用需要使用本机库的sqlitecipher库。 Their tutorial is very simple but it doesn't work for me. 他们的教程非常简单,但对我来说不起作用。 Every time I get the following error: 每次我收到以下错误:

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. 它意味着.so文件在编译期间没有附加。

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). 我认为问题在于我使用maven来管理依赖项(无论如何都要使用Android Studio进行构建)。 The next try - include those libraries into maven dependencies. 下一次尝试 - 将这些库包含在maven依赖项中。 According documentation it is pretty easy. 根据文档,这很容易。 I couldn't find them in a public repository so I used <scope>system</scope> with a tag. 我在公共存储库中找不到它们,所以我使用带有标记的<scope>system</scope> 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 后来发现这个链接,据说范围“系统”不起作用,尝试将这些库添加到本地存储库中使用

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. 我也看到了这个话题 ,可能这是一个解决方案,但我目前不使用gradle。 Is there a way to include .so files into the apk without moving from maven to gradle? 有没有办法将.so文件包含到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? 据我所知,Android Studio在内部使用gradle来构建apks,所以我对maven的所有努力都没用,直到他们开始支持本机库,我是对的吗? I have also tried building the project with Intellij IDEA Cardea (13.0), unfortunately without any success. 我还尝试用Intellij IDEA Cardea(13.0)构建项目,遗憾的是没有任何成功。

As soon as the native libs are in /libs/armeabi/ all you have to do is to configure the android plugin properly. 只要本机库在/ libs / armeabi /中,你所要做的就是正确配置android插件。 Something like this: 像这样的东西:

<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>

To Question 1 : Yes. 问题1 :是的。 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. 可以使用ant任务将SO文件添加到APK。 And since maven can run Ant tasks it possible. 由于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. 您在此处找到的nativeLibsToJar只不过是将所有SO文件放入ZIP文件然后使用扩展名JAR而不是ZIP的任务。 You can easily do that with the Ant task Zip (and maybe additionally rename ). 您可以使用Ant任务Zip轻松完成此操作 (也可以另外重命名 )。

To Question 2 : No. Because of the first answer. 问题2 :不。由于第一个答案。 There is no need for "maven to support native libraries". 没有必要“maven支持本地库”。 Just use Ant as build-system. 只需使用Ant作为构建系统。

You have to create jni folder for .so file include in android project using android studio. 你必须使用android studio为android项目中的.so文件创建jni文件夹。

I have attached image please follow these steps. 我附上图片请按照以下步骤操作。

After creating jnilib folder you can put your all .so files in this folder. 创建jnilib文件夹后,您可以将所有.so文件放在此文件夹中。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将本机库(SO文件)包装到Android存档(AAR文件)中 - Wrapping native libraries (SO files) into an Android Archive (aar file) 如何在项目android中加载两个预构建库的.so文件? - How to load .so files of two pre built libraries in project android? 如何在Android Studio中通过链接引用单个本机库(.so文件)(等级) - How to reference individual native libraries (.so files) BY LINK in Android Studio (gradle) libsupportjni.so文件中添加的文件 - libsupportjni.so files added in the project 对于Android项目,我如何使Maven拾取lib目录中的所有库,包括.so文件? - For Android project how do I get maven to pickup all libraries in lib directory including .so files? Android Library项目是否支持本机库? - Does Android Library project support native libraries? 将.so文件添加到Android项目中 - Adding .so files to Android project 如何在IntelliJ中添加多个本机库(.so)文件 - How to add multiple native libraries (.so) files in IntelliJ 项目和库中的多个Android Supprt文件 - Multiple Android Supprt files in Project and libraries 如何在Android N上动态加载NativeActivity的本机共享库(.so)? - How to dynamically load a native shared libraries (.so) for NativeActivity on Android N?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM