6

My app has several JNI modules. I use Android.mk to define modules and what files to be built for each module. So I had to disable automatic ndk-build call. My gradle contains the following:

sourceSets.main {
    jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
    jniLibs.srcDirs = ['src/main/libs']
}

task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "ndk-build.cmd",
        '-C', file('src/main/jni').absolutePath,
        '-j', Runtime.runtime.availableProcessors(),
        'all'
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn buildNative
}

Since now Android Studio support NDK and native debugging, I'd need to use new experimental gradle plugin. There's a section that I need to specify the module name.

android.ndk {
    // All configurations that can be changed in android.ndk.
    moduleName = "native"
    toolchain = "clang"
    toolchainVersion = "3.5"
    // Note that CFlags has a capital C, which is inconsistent with
    // the naming convention of other properties.  This is a
    // technical limitation that will be resolved
    CFlags += "-DCUSTOM_DEFINE"
    cppFlags += "-DCUSTOM_DEFINE"
    ldFlags += "-L/custom/lib/path"
    ldLibs += "log"
    stl = "stlport_static"
}

However, all examples I see only specify one module and there's no way to specify which file to be built against that module.

Does anybody have any idea how to define several modules and specify files for each module in this new experimental gradle plugin?

sovathee
  • 61
  • 2
  • You [***can***](http://stackoverflow.com/a/32640823/192373) keep your carefully crafted **Android.mk** scripts and still enjoy the advantages of the new *experimental* gradle plugin, including native debugging. – Alex Cohn Nov 08 '15 at 10:43
  • Create a new module for each module and add them as dependencies in your current project. I'm just posting this here in case someone else needs to know – Nick Isaacs Oct 25 '16 at 12:04

1 Answers1

0

The new experimental gradle doesn't yet support building standalone native library module.

This is a known limitation being tracker on b.android.com/177631.

proppy
  • 10,495
  • 5
  • 37
  • 66