android -- 编译不同库及编译脚本之区别
我们经常会编译不同库在不同的场合下,而也经常与第三方有合作,对方提供静态库,动态库及配置文件,也有可能需要提供库给对方等等,借此机会将所使用的一些情况作个总结。下面写的android.mk都是一些模板,可能模块可能不需要但加上也无所谓,必要时直接加即可。1、编译生成动态库
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# [optional, user, eng]
# eng = required
# optinal = no install on target
LOCAL_MODULE_TAGS := eng
# This is the target being built.
LOCAL_MODULE:= libxxx
# Target install path.
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
# All of the source files that we will compile.
LOCAL_SRC_FILES:= \
xxx.c
yyy.cpp
# All of the shared libraries we link against.
LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
liblog \
# No static libraries.
LOCAL_STATIC_LIBRARIES := \
# Also need other headers.
LOCAL_C_INCLUDES += \
frameworks/base/include/ \
# No specia compiler flags.
LOCAL_CFLAGS += -D_cplusplus
# Don't prelink this library. For more efficient code, you may want
# to add this library to the prelink map and set this to true.
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
2、编译静态库
对上在最后一名:include $(BUILD_SHARED_LIBRARY)
改成:
include $(BUILD_STATIC_LIBRARY)
3、编译生成可执行文件
最后一句修改成
include $(BUILD_EXECUTABLE)
4、编译生成jar包:
LOCAL_PATH := $(call my-dir)
# the library
# ============================================================
include $(CLEAR_VARS)
LOCAL_MODULE:= libandroidtest
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES := \
$(call all-subdir-java-files)
LOCAL_SRC_FILES += \
$(call all-java-files-under, ../gen)
#LOCAL_SRC_FILES += \
android/net/telecast/INetworkServiceManager.aidl \
### 对于aidl文件不加入到framework/base下的android.mk在线无法编译,可以提前生成aidl的java文件放在gen目录下进行编译
include $(BUILD_JAVA_LIBRARY)
5、只需要拷贝某个文件到目录下而不需要使用其中间编译结果
include $(CLEAR_VARS)
LOCAL_MODULE := libandroidtest.xml
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := ETC
# This will install the file in /system/etc/permissions
#
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
6、与5条相似,但其它库需要这个中间编译obj,这个对静态库非常重要
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
$(call add-prebuilt-files, STATIC_LIBRARIES, libchfp.a)
或者写成:
LOCAL_PATH:= $(call my-dir)
#include $(CLEAR_VARS)
#LOCAL_MODULE_TAGS := eng
#$(call add-prebuilt-files, STATIC_LIBRARIES, libchfp.a)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := libchfp.a
LOCAL_BUILT_MODULE_STEM := libchfp.a
LOCAL_MODULE_SUFFIX := lib
LOCAL_MODULE := libchfp
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
补充:移动开发 , Android ,