我是NDK Build系统的新手,虽然我非常了解GNU Make。
我正在尝试使用一个库和一个用于测试库的测试存根来为我的项目定义构建系统。
我有以下设置,哪种有效,但我对它不满意。
--------------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-----------
如果我在jni / library下运行ndk-build,但是在jni中无效,则此设置有效。从jni目录开始,它不构建库,只是删除预先存在的lib并创建一个新的空存档。
我实际上想要做以下事情。
---------------------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-----------
提前感谢您的帮助。有没有我可以通过的文件。 我没有找到任何能够详细解释构建复杂的多子目录构建系统的内容。
感谢, 阿南德
答案 0 :(得分:-1)
请按照以下步骤操作,它可能对您有帮助。
将您的c文件放入jni文件夹并创建一个新文件并将其命名为Android.mk 输入代码。
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := samplelib
LOCAL_SRC_FILES := sample.c
include $(BUILD_SHARED_LIBRARY)
samplelib是在使用此项运行项目后在libs文件夹上创建的库,应调用内部活动。
sample.c是包含导出到Activity的JNI Export方法的c文件。
3.将以下代码粘贴到sample.c文件中,
jint Java_com_example_ndkdemo_ADD (JNIEnv* env, jobject thiz,jint number1,jint number2)
{
int value = add(number1,number2);
return value;
}
在方法“Java_com_example_ndkdemo_ADD”中, Java 是关键字 com_example_ndkdemo 是包名“com.example.ndkdemo” ADD 是MethodName jint 是int值