android — 編譯不同庫及編譯指令碼之區別

來源:互聯網
上載者:User

我們經常會編譯不同庫在不同的場合下,而也經常與第三方有合作,對方提供靜態庫,動態庫及設定檔,也有可能需要提供庫給對方等等,藉此機會將所使用的一些情況作個總結。下面寫的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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.