android NDK 使用(多个)静态库生成动态库。
1、编写Android.mk文件:如下两种方式都可以,用于NDK编译工具生成的两个.a文件来生成最终的libtwolib-second.so动态库。
LOCAL_PATH:=$(callmy-dir)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-second
LOCAL_SRC_FILES:=second.c
LOCAL_LDFLAGS:=first.athird.a
LOCAL_LDLIBS:=-L$(SYSROOT)/usr/lib-llog
include$(BUILD_SHARED_LIBRARY)
方式二:
LOCAL_PATH:=$(callmy-dir)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-first
LOCAL_SRC_FILES:=first.a
include$(PREBUILT_STATIC_LIBRARY)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-third
LOCAL_SRC_FILES:=third.a
include$(PREBUILT_STATIC_LIBRARY)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-second
LOCAL_SRC_FILES:=second.c
LOCAL_STATIC_LIBRARIES:=libtwolib-firstlibtwolib-third
LOCAL_LDLIBS:=-L$(SYSROOT)/usr/lib-llog
include$(BUILD_SHARED_LIBRARY)
2、生成动态库
# Android.mk for FFmpeg
# Lei Xiaohua à×???è
# leixiaohua1020@126.com
# https://blog.csdn.net/leixiaohua1020
#
LOCAL_PATH := $(call my-dir)
# FFmpeg library
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES := libavcodec-57.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avdevice
LOCAL_SRC_FILES := libavdevice-57.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avfilter
LOCAL_SRC_FILES := libavfilter-6.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avformat
LOCAL_SRC_FILES := libavformat-57.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avresample
LOCAL_SRC_FILES := libavresample-3.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := libavutil-55.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swresample
LOCAL_SRC_FILES := libswresample-2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES := libswscale-4.so
include $(PREBUILT_SHARED_LIBRARY)
# Program
include $(CLEAR_VARS)
LOCAL_MODULE := sffstreamer
LOCAL_SRC_FILES :=simplest_ffmpeg_streamer.c
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog -lz
LOCAL_SHARED_LIBRARIES := avcodec avdevice avfilter avformat avutil avresample swresample swscale
include $(BUILD_SHARED_LIBRARY)
附:
可以直接编写Android.mk文件来生成两个.a文件,如下:
LOCAL_PATH:=$(callmy-dir)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-first
LOCAL_SRC_FILES:=first.c
include$(BUILD_STATIC_LIBRARY)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-third
LOCAL_SRC_FILES:=third.c
include$(BUILD_STATIC_LIBRARY)
include$(CLEAR_VARS)
LOCAL_MODULE:=libtwolib-second
LOCAL_SRC_FILES:=second.c
LOCAL_STATIC_LIBRARIES:=libtwolib-firstlibtwolib-third
LOCAL_LDLIBS:=-L$(SYSROOT)/usr/lib-llog
include$(BUILD_SHARED_LIBRARY)