jasonsemko
jasonsemko

Reputation: 743

Android NDK: Header file error, no such file or directory

Using a C library in an Android application. Header files seem to be listed fine in LOCAL_C_INCLUDES but NDK is not picking up on them. What concerns me as well is that I can delete the contents of the entire Android.mk file and I still get the same error. (maybe that's the issue?)

Screenshot here is of my Android.mk file, the proof the header file is present, and the error message. Everything seems to be in order but still not working:

https://www.evernote.com/l/ALfUcInkbU5KcalFLvRnhfNPMqROk8w2bAAB/image.png

Thanks! I will be checking back and can provide text snippets if needed.

Upvotes: 0

Views: 2053

Answers (1)

ph0b
ph0b

Reputation: 14473

You're using Android Studio, and AS with the current gradle plugin ignores your Android.mk/Application.mk files. That's why the ndk can't find the headers.

You can simply deactivate the built-in call to ndk-build with the autogenerated Makefiles, and make gradle call ndk-build directly, taking your Makefiles in account:

import org.apache.tools.ant.taskdefs.condition.Os

...

android {  
  ...
  sourceSets.main {
        jniLibs.srcDir 'src/main/libs' //set .so files location to libs instead of jniLibs
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    // add a task that calls regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

    // add this task as a dependency of Java compilation
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}

Upvotes: 2

Related Questions