How to properly add pre-created static library to Android NDK Android.mk?

I was stuck when my libraries entered the Android NDK assembly.

Libraries compile correctly and work fine when creating a dummy cpp file and build everything with the direct g ++ command in the shell.

The current Android.mk file does not work and gives an error that the corresponding header files (which are part of the .a files) cannot be found.

How to enable ready-made static libraries?

My Android.mk file looks like this:

LOCAL_PATH := $(call my-dir) # V8 Base include $(CLEAR_VARS) LOCAL_MODULE := v8_base LOCAL_MODULE_FILENAME := v8_base_static LOCAL_SRC_FILES := ../lib/libv8_base.a include $(PREBUILT_STATIC_LIBRARY) # V8 Nosnapshot include $(CLEAR_VARS) LOCAL_MODULE := v8_nosnapshot LOCAL_MODULE_FILENAME := v8_nosnapshot_static LOCAL_SRC_FILES := ../lib/libv8_nosnapshot.a include $(PREBUILT_STATIC_LIBRARY) # V8GL Runtime include $(CLEAR_VARS) LOCAL_MODULE := v8gl-runtime LOCAL_SRC_FILES := main.c ../src/v8gl/v8gl.cpp LOCAL_CPPFLAGS := -D__ANDROID__ LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM LOCAL_STATIC_LIBRARIES := android_native_app_glue v8_base v8_nosnapshot # LOCAL_EXPORT_CPPFLAGS := -D__ANDROID__ include $(BUILD_SHARED_LIBRARY) $(call import-module,android/native_app_glue) 

The compiler output is the following, which makes sense, but only shows me that there is not a single .a file, and I don’t know why:

 Compile++ thumb : v8gl-runtime <= v8gl.cpp (... g++ call) In file included from jni/../src/v8gl/v8gl.cpp:6: jni/../src/v8gl/v8gl.h:5:16: error: v8.h: No such file or directory 

SOLUTION with an absolute path

Thanks to a hint of @ alex-cohn, I found out that attachments were falsely marked. Therefore, I decided to use an environment variable that was set before calling ndk-build, which contains an absolute path. This fixes the problem with the included ones.

So, the last module where the actual inclusion is performed now looks like this:

 ADK_PATH=/var/whatever/to/your/project/root_not_jni include $(CLEAR_VARS) LOCAL_MODULE := v8gl-runtime LOCAL_SRC_FILES := main.c ../src/v8gl/v8gl.cpp LOCAL_C_INCLUDES:= $(ADK_PATH)/external/v8/include LOCAL_CPPFLAGS := -D__ANDROID__ LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM LOCAL_STATIC_LIBRARIES := android_native_app_glue v8_base v8_nosnapshot 

Now it also shows that libraries are included because they are compiled subsequently - for any reason.

SOLUTION with a relative path

All included paths refer to the project root folder, not the jni folder. This means that it will land as a compiler. I flag something like this:

 LOCAL_C_INCLUDES := $(LOCAL_PATH)/../file_in_project.root # resulting g++ flag: -Ijni/../file_in_project.root 

So there is a difference between the relative include and LOCAL_SRC_FILES paths that belong to the jni folder!

+6
source share
1 answer

You probably have a v8.h file in the v8.h directory or somewhere else ...

You must add a line

 LOCAL_C_INCLUDES = $(LOCAL_PATH)/../include 

Please note that unlike LOCAL_SRC_FILES , where you do not need $(LOCAL_PATH) , here you must put the full paths of all directories where the necessary .h files are located.

+4
source

Source: https://habr.com/ru/post/925172/


All Articles