I am a newbie to NDK Build system, although I know GNU Make quite well.
I am trying to define build system for my project with one Library and a test stub for testing the library.
I have the following setup, which sort of works but I am not happy with it.
--------------jni/Android.mk--------------
# A simple test for the minimal standard c library
LOCAL_PATH := $(call my-dir)
MY_LOCAL_PATH := $(LOCAL_PATH)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/library/Android.mk
---------------jni/Android.mk------------------
-------------jni/library/Android.mk----------------------
# A simple test for the minimal standard c library
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -g -DDEBUG
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc
LOCAL_MODULE := lteDiag
LOCAL_SRC_FILES := $(wildcard src/*.c)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -g -DDEBUG
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc
LOCAL_MODULE := DiagAppf
LOCAL_SRC_FILES := ../test_stub/test.c
LOCAL_STATIC_LIBRARIES := lteDiag
include $(BUILD_EXECUTABLE)
----------------------jni/library/Android.mk-----------
This setup works if I run ndk-build under jni/library, but doesn't work from jni. From jni directory it does not build the library and simply removes the preexisting lib and creates a new empty archive.
I would actually want to do the following.
---------------------jni/Android.mk---------------
# A simple test for the minimal standard c library
LOCAL_PATH := $(call my-dir)
MY_LOCAL_PATH := $(LOCAL_PATH)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/DM_Library/Android.mk
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -g -DDEBUG
LOCAL_PATH := $(MY_LOCAL_PATH)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/DM_Library/inc
LOCAL_MODULE := DiagAppf
LOCAL_SRC_FILES := test_stub/test.c
LOCAL_STATIC_LIBRARIES := lteDiag
include $(BUILD_EXECUTABLE)
---------------jni/Android.mk---------------
-----------------jni/library/Android.mk-----------------
# A simple test for the minimal standard c library
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -g -DDEBUG
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc
LOCAL_MODULE := lteDiag
LOCAL_SRC_FILES := $(wildcard src/*.c)
include $(BUILD_STATIC_LIBRARY)
--------------------jni/library/Android.mk-----------
Thanks in advance for any help. Is there any documentation that I can go through. I am not finding anything that explains in detail building of a complex multiple subdirectory build system.
thanks, Anand
Kindly follow below steps, It may helps you.
Put your c file inside the jni folder and create a new file and name it as Android.mk type the Code.
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := samplelib LOCAL_SRC_FILES := sample.c include $(BUILD_SHARED_LIBRARY)
samplelib is the library created on libs folder after running project using this u should call inside activity.
sample.c is the c file that contains the JNI Export methods that is important to export to Activity.
3.Paste follwoing codes into sample.c file,
jint Java_com_example_ndkdemo_ADD (JNIEnv* env, jobject thiz,jint number1,jint number2)
{
int value = add(number1,number2);
return value;
}
In method "Java_com_example_ndkdemo_ADD" , Java is Keyword com_example_ndkdemo is the package name "com.example.ndkdemo" ADD is the MethodName jint is int value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.