Building NDK *.so's and including in the APK the Gradle way

169 views
Skip to first unread message

William Damage

unread,
Jun 2, 2014, 4:39:25 AM6/2/14
to gradle-androi...@googlegroups.com
Hi,

I'm converting a rather large project which has been previously managed using Maven, and imported into AS using that as a builder. It builds fine, and I'm even on the latest canary (currently 0.5.9). There are 3 NDK modules, spread over 2 Android.mk files, and the resulting APK entries are /lib/armeabi/foo1.so, foo2.so and foo3.so and the same in \lib\armeabi-v7a. 

The problem is I can only seem to create these *.so files using Maven if I explicitly invoke the NDK for each one, so in Windows the line is
  commandLine 'ndk-build.cmd', '-C', System.getProperty("user.dir")  + '/bar/foo1 and then separately  commandLine 'ndk-build.cmd', '-C', System.getProperty("user.dir")  + '/bar/foo2. This seems wrong, and I still have the problem of copying the *.so files from wherever they are created this way to where ever the APK packager needs them to be in order to recreate exactly the current deployed /lib armeabi .. files.

I suspect there is full support for this and all I need to so is grasp how the jniLibs.srcDir or jni.srcDirs entries should work in my situation and all this is done automatically in Gradle. And also, what the ndk { ... } entry in the defaultConfig { } clause is used for, because right now I'm not using any of those. Anyone spot what I need please?

William Damage

unread,
Jun 3, 2014, 4:02:13 AM6/3/14
to gradle-androi...@googlegroups.com


On Monday, 2 June 2014 09:39:25 UTC+1, William Damage wrote:
<snip>
And also, what the ndk { ... } entry in the defaultConfig { } clause is used for, because right now I'm not using any of those. Anyone spot what I need please? 
</snip> 

Got further and realise now what the real problem is -  how to specify multiple modules? Here's the config which gives me the closest to what I want so far, bearing in mind there are 3 modules:

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        ndk {
           moduleName "foo1"
           //moduleName "foo2"
           //moduleName "foo3"
           ldLibs "log", "z", "m"
           abiFilters "armeabi", "armeabi-v7a"
        }
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [
            '/Features/fool1/jni'
            //'/Features/foo2/jni'
            //'/Features/foo3/jni'
        ]
    }

If I try to use the other modules by uncommenting the appropriate lines above I find either the syntax fails or just the latest in the list of ndk modules is added. What exactly does "moduleName" in the ndk entry do?

Reply all
Reply to author
Forward
0 new messages