How to include versioned *.so file into apk using Gradle?

旧街凉风 提交于 2021-02-18 23:45:50

问题


I trying to build android application with some precompiled native libraries: liba.so and 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.

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


回答1:


Unfortunately I don't develop for Android anymore, so I can't test this, but I know Gradle and this might work for you. Looking at the Android DSL docs, you might be able to change the filtering on the jniLibs folder:

android {
    sourceSets {
        main {
            jniLibs.filter.include("**/*")
        }
    }
}

Let me know if this works!




回答2:


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.

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




回答3:


Just add the jniLibs folder in app/src/main and it will include the .so file in the apk.

/app/src/main/armeabi/*.so files



来源:https://stackoverflow.com/questions/42813480/how-to-include-versioned-so-file-into-apk-using-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!