本机库(.so 文件)未添加到 android 项目中 [英] Native libraries (.so files) are not added to an android project

查看:38
本文介绍了本机库(.so 文件)未添加到 android 项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用需要使用本机库的 sqlitecipher 库.他们的教程非常简单,但对我不起作用.每次我收到以下错误:

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:

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)

表示编译时没有附加.so文件.

it means .so files were not attached during compilation.

所有 3 个文件都存储在/libs/armeabi/目录中.

all 3 files are stored in /libs/armeabi/ directory.

我认为问题在于我使用 maven 来管理依赖项(无论如何构建都是使用 Android Studio 执行的).下一次尝试 - 将这些库包含到 Maven 依赖项中.根据文档,这很容易.我在公共存储库中找不到它们,所以我使用了 system带标签.它们是可见的,但没有用.后来发现这个链接据说范围系统"不起作用,尝试使用

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

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.

我也看到了这个主题,可能这是一个解决方案,但我目前不使用 gradle.有没有办法在不从 maven 移动到 gradle 的情况下将 .so 文件包含到 apk 中?

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?

据我所知,Android Studio 在内部使用 gradle 来构建 apk,所以我在 maven 上的所有努力都是无用的,直到它们开始支持本机库,对吗?我还尝试使用 Intellij IDEA Cardea (13.0) 构建项目,但不幸的是没有成功.

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.

推荐答案

只要原生库位于/libs/armeabi/中,您所要做的就是正确配置 android 插件.像这样:

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:

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

这篇关于本机库(.so 文件)未添加到 android 项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆