最近在研究ndk开发,需要编译动态库so或者静态库.a文件,就在Android.mk文件中配置,
LOCAL_PATH := $(call my-dir)
#加载动态库
include $(CLEAR_VARS)
LOCAL_MODULE := curl
LOCAL_SRC_FILES := libcurl.so
include $(PREBUILT_SHARED_LIBRARY)# PREBUILT_SHARED_LIBRARY动态库
# 加载静态库
include $(CLEAR_VARS)
LOCAL_MODULE := soundiotarch
LOCAL_SRC_FILES := libsoundiot_sdk_arch64.a
include $(PREBUILT_STATIC_LIBRARY) # PREBUILT_STATIC_LIBRARY静态文件
# Program
include $(CLEAR_VARS)
LOCAL_MODULE := soundplus #编译so库名字
LOCAL_SRC_FILES :=com_aitek_soundplus_sound_SoundDenoise.c #自己的c文件
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include #头文件搜索路径
LOCAL_LDLIBS :=-llog -lz #附加的链接器选项
LOCAL_STATIC_LIBRARIES := curl soundiotarch #编译上面两个lib
include $(BUILD_SHARED_LIBRARY) #$(BUILD_STATIC_LIBRARY)编译成so库或者.a文件
最后加载
package com.aitek.soundplus.sound;//c文件提供native方法必须包名一样
public class SoundDenoise {
static {
System.loadLibrary("soundplus");
}
}
网友评论