Ronald Wiplinger Ronald Wiplinger - 10 months ago 184
Android Question

How to include *.so library in Android Studio?

I read many threads how to add a *.so library to Android Studio, but none of them works, especially when it comes to the point of text: This does not work with the newer xxx (Android Studio, gradle, ...)

Can we make a fresh start please. I got:

Android Studio 0.6.0

From Project Structure I see:

SDK Location:



Gradle version 1.10
Android Plugin Version 0.11.+


Compile Sdk Version 19
Build Tools Version 19.1.0


{dir=libs, include=[*.jar]} Compile

{dir=libs, include=[*.so]} Provided

m appcompat -v7:19.+ Compile

I got the *.so files pre-compiled and at the demo app they are working. I have to change the source code of the app, so I need to rebuild with the same *.so files.


Add both code snippets in your module file as a dependency:

compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')

How to create this custom jar:

task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    from fileTree(dir: 'libs', include: '**/*.so')
    into 'lib/'

tasks.withType(Compile) {
    compileTask -> compileTask.dependsOn(nativeLibsToJar)

Same answer can also be found in related question: Include .so library in apk in android studio