How to Add .So Files to an Android Library Project Using Gradle 0.7+

How can I add .so files to an android library project using gradle 0.7+

In the end I didnt need to use product flavours.

For the library project I added the following:

android {
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}

The libs folder had a folder inside called "armeabi-v7a" and as this is my only target it worked a treat.

The ndk files (.so) are propagated into the android project that is using the android library project.

Add pre-built .so files in project using Android Gradle plugin 0.7.3

So how you can add the pre-built .so files ?

1) Upgrade your android studio to 0.4.0

2) Replace "distributionUrl=" in gradle-wrapper.properties with "distributionUrl=http://services.gradle.org/distributions/gradle-1.9-all.zip"

3) Add/Replace your 'buildscript' section build.gradle with:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.3'
}
}

4) Add the jniLibs folder in ../src/main/

5) Add the following in your build.gradle:

android {
compileSdkVersion 18
buildToolsVersion "18.1.0"

defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}

productFlavors {
x86 {
ndk {
abiFilter "x86"
}
}
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}

}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
}

6) Build your project.

Adding a .so file in Android Studio

You can add pre built *.so files in Android Studio using gradle 0.7.2+. First create the jniLibs at this location /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs.

Sample Image

Include .so library in apk in android studio

I had the same problem. Check out the comment in https://gist.github.com/khernyo/4226923#comment-812526

It says:

for gradle android plugin v0.3 use "com.android.build.gradle.tasks.PackageApplication"

That should fix your problem.

Android Studio - include and consume .so library

Thank you guys for helping but it was a stupid problem. When I imported my .so files under jniLibs, they were named like libSONAME.so. In these lines of code:

static {
System.loadLibrary("libSONAME");
}

we should not use System.loadLibrary("libSONAME");, but just System.loadLibrary("SONAME");.

Then, just build the project and everything was OK.

Thank you all for helping. I hope this will save time to someone else.



Related Topics



Leave a reply



Submit