WhyWhyWhy
WhyWhyWhy

Reputation: 115

Android Studio/Gradle is not packing my shared library named "mylib.so.1" in APK

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}.

Upvotes: 2

Views: 1508

Answers (2)

KeloCube
KeloCube

Reputation: 76

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.

Upvotes: 1

shizhen
shizhen

Reputation: 12583

You need to make the suffix be exactly .so. So remove the redundant .1

Upvotes: 1

Related Questions