3

I need to do a simple thing: include .so in the project. Here's what I have now:

# app/build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "my.app.123"
        minSdkVersion 14
        targetSdkVersion 22

        versionCode 7113
        versionName "7113"
    }


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

    }
}



dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'io.pristine:libjingle:8871'
}

# build.gradle
all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

And I have these "so" files in src/src/main/jniLibs:

   /arm64-v8a/file1_so.so
   /armeabi-v7a/file1_so.so
   /x86/file1_so.so
   /x86_64/file1_so.so

However, when I launch my application I get an error which implies the application is using the "old" so file which already has been embedded into it before. So I'm unsure any of these files are getting compiled into the result apk at all.

What should I do to include them into the output apk for sure?

Incerteza
  • 32,326
  • 47
  • 154
  • 261

1 Answers1

7

Here is how I bring in my prebuilt *.so into my apps, just make sure your *.so are in the src/main/libs folder:

android {
    ...
    sourceSets {
        //noinspection GroovyAssignabilityCheck
        main {
            jni {
                srcDirs = []
            }

            jniLibs {
                srcDir 'src/main/libs'
            }
        }
    }
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185