Search code examples
cmakefileandroid-ndkjava-native-interface

NDK-Use of .a file in C file


I'm trying to use a .a file in my C code to use in Java (sorry for my bad English). I created myself a static library named libtest.a. now when i include files present in that library in gives me error as no such file or directory.

i have put the libtest.a in the same folder where my Android.mk and Application.mk resides

C-code:

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include <exp.h> //the header in libtest.a

And this is my makefile:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libtest
LOCAL_SRC_FILES := libtest.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := socket
LOCAL_SRC_FILES := source/interface.c source/file.c
LOCAL_LDFLAGS += libtest.a  

include $(BUILD_SHARED_LIBRARY)

When I compile it, I get the following error

error: exp.h: No such file or directory

I want to use the .a without it's code so I hope I'm clear enough.


Solution

  • as i have changed my .mk file

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := libtest
    LOCAL_SRC_FILES := libtest.a
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../libtest/jni/include
    include $(PREBUILT_STATIC_LIBRARY)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := socket
    LOCAL_SRC_FILES := source/interface.c source/file.c
    LOCAL_STATIC_LIBRARIES += libtest
    include $(BUILD_SHARED_LIBRARY)