最近做JNI调用第三方so中的c方法,总是报找不到so文件,今天终于解决了,总结如下:
一、在根目录下建立Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := xxx
LOCAL_JNI_SHARED_LIBRARIES := libxxx
include $(BUILD_PACKAGE)
IN_NDK := true
WITH_PLAYER := true
include $(call all-makefiles-under,$(LOCAL_PATH))
二、在项目下jni文件夹里Android.mk;
include $(all-subdir-makefiles)
三、在jni文件夹下新建目录prebuilt(或者其他别名)将所有的第三方库复制进去,并建Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libx264
#LOCAL_STATIC_LIBS
LOCAL_SRC_FILES := libx264.a
include $(PREBUILT_STATIC_LIBRARY) #(静态库)
include $(CLEAR_VARS)
LOCAL_MODULE := libLinePhone
LOCAL_SRC_FILES := libLinePhone.so
include $(PREBUILT_SHARED_LIBRARY) #(动态库)
四、在jni文件夹下新建目录jni(或其他别名)中放所有的c文件(含调用及本地方法的),Android.mk写法如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
IN_NDK := true
LOCAL_CFLAGS := -D__STDC_CONSTANT_MACROS
WITH_CONVERTOR := true
WITH_PLAYER := true
ifeq ($(WITH_PLAYER),true)
LOCAL_CFLAGS += -DBUILD_WITH_PLAYER
endif
ifeq ($(WITH_CONVERTOR),true)
LOCAL_CFLAGS += -DBUILD_WITH_CONVERTOR
endif
LOCAL_C_INCLUDES += xxx
LOCAL_SRC_FILES := xx.cpp
ifeq ($(IN_NDK),true)
LOCAL_LDLIBS := -llog
else
LOCAL_PRELINK_MODULE := false
LOCAL_SHARED_LIBRARIES := liblog
endif
LOCAL_SHARED_LIBRARIES :=xxxxx
LOCAL_STATIC_LIBRARIES :=xxxxx
LOCAL_MODULE := xxx
include $(BUILD_SHARED_LIBRARY)