Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 261
kostashv Avatar asked Mar 15 '17 15:03

kostashv


2 Answers

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.

like image 72
alex Avatar answered Nov 04 '22 03:11

alex


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!

like image 45
MartinTeeVarga Avatar answered Nov 04 '22 04:11

MartinTeeVarga