Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android.bp: how to add external header .h files

I have a similar problem as How to add external header files during bazel/tensorflow build. but I hope there is a better solution.

I have a module that requires some external .h header files at other location. Suppose I try to include "vendor/external/include/thirdpary.h", In Android.bp, I add some line like:

include_dirs: [
"vendor/external/include",
]

But the compiler is complaining this file does not exist when I include it in my CPP file:

#include "thirdpary.h"
like image 944
user2271769 Avatar asked Dec 04 '18 05:12

user2271769


1 Answers

Using include_dirs is the correct approach. From what you write in your description it should work.

Here are some suggestions for error checking:

Is vendor/external/include actually a subfolder of $ANDROID_BUILD_TOP?

Directories in include_dirs have to be specified relatively to the AOSP root directory. If the path is relative to your Android.bp you have to use local_include_dirs instead.

cc_binary {
    name: "my-module",
    srcs: [ "main.cpp" ],
    include_dirs: [ "vendor/external/include" ]
}

Is the cpp file in the srcs list of the same module definition as include_dirs?

If you want to inherit the include directory from a library your module depends on, then the library should use export_include_dirs.

cc_library {
    name: "my-library",
    export_include_dirs: [ "include" ]
}

cc_binary {
    name: "my-module",
    srcs: [ "main.cpp" ],
    static_libs: [ "my-library"] 
}

What include dirs are provided to the compiler when you build your module?

Rebuild your module and check the -I options.

m my-module | grep "main.cpp" | sed 's/-I/\n-I/g'
like image 91
Simpl Avatar answered Oct 14 '22 14:10

Simpl