Android - Conditional execution of externalNativeBuild possible?

397 Views Asked by At

Using Kotlin DSL, does anyone know how I can tell Gradle to only execute the instructions in my library module's externalNativeBuild block if a) CMakeLists.txt is present? or b) based on buildType (debug no, release yes).

I've tried moving the externalNativeBuild block into buildTypes block, but this did not work. I've also tried several variations of something like this:

val cMakePath = "src/main/cpp/CMakeLists.txt"
    if (File(cMakePath).exists()) {
        externalNativeBuild {
            cmake {
                path(cMakePath)
            }
        }
    }

(In my specific setup, CMakeLists.txt gets generated during release builds, the native part is only present for release builds. That's why I tried it this way.)

But even if Gradle is happy - as in no compiler warnings or errors, with every conditional solution I try, at startup my app fails because

java.lang.UnsatisfiedLinkError: dlopen failed: library "mylibrary.so" not found

so obviously the native lib doesn't get built.

How can I achieve my desired behaviour?

0

There are 0 best solutions below