我有一个构建问题,特别是使用 Maven 构建环境。我正在使用 Android NDK (r10e) 构建一个 Android 库。我正在为 Android 6.0 (API 23) 构建。虽然在我的主项目中使用这个库并将其放到我的平板电脑上后,我收到以下错误:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libgnustl_shared.so" not found
我的 Application.mk 是:
APP_ABI := all
APP_STL:=gnustl_shared
APP_CPPFLAGS += -std=c++11
我的 maven 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>myParent</artifactId>
<groupId>com.test.android</groupId>
<version>1.05</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>myNativeLib</artifactId>
<packaging>so</packaging>
<name>testNativeLib</name>
<properties>
<android.ndk.args>V=1 -B NDK_DEBUG=1 -j8</android.ndk.args>
<arch>armeabi-v7a armeabi</arch> <!-- TODO add more arch types -->
<mavenAntrunPluginVersion>1.8</mavenAntrunPluginVersion>
<includes.version>1.0.6</includes.version>
<sonar.sources>src,pom.xml</sonar.sources>
</properties>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-ndk-maven-plugin</artifactId>
<version>1.0.1-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<target>${project.artifactId}</target>
<finalLibraryName>${project.artifactId}</finalLibraryName>
<ndkPath>${android.ndk.path}</ndkPath>
<!-- so jenkins parameter -Dandroid.ndk.path actually works. -->
<applicationMakefile>src/main/cpp/Application.mk</applicationMakefile>
<makefile>src/main/cpp/Android.mk</makefile>
<architectures>${arch}</architectures>
<additionalCommandline>${android.ndk.args}</additionalCommandline>
<librariesOutputDirectory>${project.build.directory}/ndk-libs</librariesOutputDirectory>
<objectsOutputDirectory>${project.build.directory}/ndk-obj</objectsOutputDirectory>
<headerFilesDirectives>
<headerFilesDirective>
<directory>${basedir}/src/main/cpp</directory>
<includes>
<include>**\/*.hpp</include>
</includes>
</headerFilesDirective>
</headerFilesDirectives>
</configuration>
</plugin>
</plugins>
</build>
<!-- placeholder -->
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>performRelease</name>
</property>
</activation>
<properties>
<android.ndk.args>V=1 -B -j8</android.ndk.args>
</properties>
</profile>
</profiles>
</project>
现在,这会生成我想要的 .so 并将其放入我的 .m2(存储库)文件夹中。然后我转到我的主要项目,它构建得很好。在我将它放在平板电脑上并启动它(它尝试加载库的地方)之后,它就失败了。在这个设置中,我没有看到关于这个问题的任何内容。我见过的最接近的东西是这个死线程:
Android Studio: java.lang.UnsatisfiedLinkError: dlopen failed
这不是很有帮助。重要的是要注意,这适用于我的 Android 4.0 实现 (API 18)。只是不在 6.0 上。查看 apk,我可以在
中看到 .solib\armeabi-v7a\testNativeLib.so
有什么想法吗?我被困在这里。
最佳答案
连同您的库,APK 必须包含 STL 运行时,在您的情况下为 libgnuSTL_shared.so
。如果您只为 armeabi 使用它,这可能是您崩溃的原因。
另一个区别是,在 API 18 中,您必须从 Java 中单独加载 STL 库,当时它不能很好地处理依赖关系。
顺便说一句,你的库真的命名为 testNativeLib.so
吗?如果没有 lib
前缀,它将无法正确安装。
关于Android 库 : java. lang.UnsatisfiedLinkError:dlopen 失败:找不到库 "libgnuSTL_shared.so",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53105361/