本文介绍了如何使用 Gradle 将版本化的 *.so 文件包含到 apk 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用一些预编译的本机库构建 android 应用程序:liba.solibb.so.1.2.3

I trying to build android application with some precompiled native libraries:liba.so and libb.so.1.2.3

库被放置在 jniLibs 子目录中.构建APK文件后,只包含liba.so,而不包含libb.so.1.2.3.

Libraries are placed into jniLibs subdirectory.After building APK file, only liba.so included into it, but not libb.so.1.2.3.

结果可想而知.应用程序在启动时崩溃.

Result is predictable. Application crashes at start.

如何使用构建脚本将 jniLibs 中的所有文件包含到 APK 中?

What to do with build scripts to include all files from jniLibs into APK?

推荐答案

由于在 Android Gradle插件,使用jniLibs 文件夹不能包含除.so 文件以外的任何内容.即使您以某种方式将库添加到 APK,Android 上的动态加载器非常有限并且很可能无法加载它们.

Due to the native library regex ^.+\\.so$ being used in the Android Gradle plugin, it is impossible to include anything other than .so files using the jniLibs folder. And even if you were to somehow add the library to the APK, the dynamic loader on Android is very limited and will most likely not be able to load them.

最好的办法是通过重命名库并更改其内部soname 在链接到它之前来完全删除该版本.

Your best bet is to remove the version altogether by renaming the library and changing its internal soname before linking against it.

这篇关于如何使用 Gradle 将版本化的 *.so 文件包含到 apk 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:04