androidandroid-ndkandroid-gradle-plugin

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


Project structure:

App project --> depends on Library project

Library Project has a folder for the compiled jni libs

jniLibs.srcDirs = ['libs']

And I've tried adding the following to the android element of the build.gradle as per the example app https://android.googlesource.com/platform/tools/build/+/2e1f7810edd76d92cee8d3e06bc4dec0c288adea/tests/ndkSanAngeles/build.gradle however android library projects do not support productFlavours and as such the assemble fails with "Could not find method productFlavors() for arguments [dghdhd] on project"

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

Is there a way to add ndk support to an android library project?


Solution

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