I need to pack a shared library named "mylib.so.1" into APK,but apparently gradle does not recognize ".so.1" extension, only ".so" and at runtime I need the library named ".so.1" to avoid linker errors. All libs are in src/main/jniLibs/${ANDROID_ABI}.
Asked
Active
Viewed 1,117 times
2 Answers
1
You need to make the suffix be exactly .so. So remove the redundant .1

shizhen
- 12,251
- 9
- 52
- 88
-
If I do this, at runtime I get a linker error, "mylib.so.1 missing" in logcat. – WhyWhyWhy Nov 04 '18 at 05:09
-
2You need to remove the suffix *and* relink anything that was linked against it. Removing the suffix post build is not sufficient. Also check that the SONAME of the library is correct (follow https://stackoverflow.com/a/48291044/632035). – Dan Albert Nov 05 '18 at 20:34
0
I was able to package versioned .so files by adding them as resources via
sourceSets.main {
resources.srcDir 'src/main/external'
}
inside the android
block in app.gradle
. Alternatively one could use resources.srcDirs += ['src/main/whatever']
.
This copies all files at the specified path to the root of the package, so the source libraries would have to be placed at src/main/external/lib/armeabi-v7a/libsomething.so.1.2.3
etc. in order to be copied to /lib/armeabi-v7a/libsomething.so.1.2.3
in the .apk
or .aar
.
Except, somewhat ironically, it doesn't seem to copy files which are presumed to be libraries (i.e. files matching *.so and possibly others). So you'll have to put your .so's in src/jniLibs
.

KeloCube
- 56
- 2
- 5