NDK<第十篇>:Android.mk和Android.bp对应关系

Android.bp文件是Android系统的一种编译配置文件,是用来代替原来的Android.mk文件的。

【1】字符串表示
mk:
    chips_dir := ../../../frameworks/opt/chips/res
bp:
    chips_dir = ["../../../frameworks/opt/chips/res"]


mk:
    res_dirs := $(chips_dir) $(color_picker_dir) $(timezonepicker_dir) res
bp:
    res_dirs = chips_dir + color_picker_dir + timezonepicker_dir + ["res"]


mk:
    src_dirs := src
bp:
    src_dirs = ["src"]
【2】mk和bp模块对应表
include $(BUILD_SHARED_LIBRARY) -> cc_library_shared {}

include $(BUILD_STATIC_LIBRARY) -> cc_library_static{}

include $(BUILD_HOST_SHARED_LIBRARY) -> cc_library_host_shared{}

include $(BUILD_HOST_STATIC_LIBRARY) -> cc_library_host_static{}

include $(BUILD_HEADER_LIBRARY) -> cc_library_headers{}

include $(BUILD_EXECUTABLE) -> cc_binary{}

include $(BUILD_HOST_EXECUTABLE) -> cc_binary_host{}

include $(BUILD_NATIVE_TEST) -> cc_test{}

include $(BUILD_HOST_NATIVE_TEST) -> cc_test_host{}

include $(BUILD_NATIVE_BENCHMARK) -> cc_benchmark{}

include $(BUILD_HOST_NATIVE_BENCHMARK) -> cc_benchmark_host{}

include $(BUILD_JAVA_LIBRARY) -> java_library_installable{}

include $(BUILD_STATIC_JAVA_LIBRARY) -> java_library{}

include $(BUILD_HOST_JAVA_LIBRARY) -> java_library_host{}

include $(BUILD_HOST_DALVIK_JAVA_LIBRARY) -> java_library_host_dalvik{}

include $(BUILD_PACKAGE) -> android_app{}

include $(BUILD_RRO_PACKAGE) -> runtime_resource_overlay{}

include $(BUILD_CTS_EXECUTABLE) -> cc_binary{}      

include $(BUILD_CTS_SUPPORT_PACKAGE) -> cts_support_package{}  

include $(BUILD_CTS_PACKAGE) -> cts_package{} 

include $(BUILD_CTS_TARGET_JAVA_LIBRARY) -> cts_target_java_library {}

include $(BUILD_CTS_HOST_JAVA_LIBRARY) -> cts_host_java_library{}
【3】mk和bp prebuilt 对应表
"SHARED_LIBRARIES": "cc_prebuilt_library_shared",
"STATIC_LIBRARIES": "cc_prebuilt_library_static",
"EXECUTABLES":      "cc_prebuilt_binary",
"JAVA_LIBRARIES":   "java_import",
"APPS":             "android_app_import",
"ETC":              "prebuilt_etc",
【4】mk和bp属性对应表
LOCAL_PACKAGE_NAME := Calendar -> name: "Calendar"
==================================================
LOCAL_JACK_COVERAGE_INCLUDE_FILTER := com.android.calendar.* ->     jacoco: { include_filter: ["com.android.calendar.*"],}
==================================================
mk:
    LOCAL_SRC_FILES := $(call all-java-files-under, src)
bp:
    srcs: ["src/**/*.java"],
==================================================
mk:
LOCAL_STATIC_JAVA_LIBRARIES := \
        android-common \
        libchips \
        colorpicker \
        android-opt-timezonepicker \
        androidx.legacy_legacy-support-v4 \
        calendar-common
bp:
static_libs: [
    "android-common",
    "libchips",
    "colorpicker",
    "android-opt-timezonepicker",
    "androidx.legacy_legacy-support-v4",
    "calendar-common",
],
==================================================
LOCAL_SDK_VERSION := current ->     sdk_version: "current",
==================================================
mk:
LOCAL_NOTICE_FILE  := $(LOCAL_PATH)/NOTICE
dp:
notice: LOCAL_PATH + "/NOTICE",
==================================================
mk:
# 混淆规则配置文件
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
bp:
optimize: {
    proguard_flags_files: ["proguard.flags"],
},
==================================================
# true:将apk安装到priv-app下
LOCAL_PRODUCT_MODULE := true -> product_specific: true,
==================================================
mk:
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips
LOCAL_AAPT_FLAGS += --extra-packages com.android.colorpicker
LOCAL_AAPT_FLAGS += --extra-packages com.android.timezonepicker

bp:
aaptflags: ["--auto-add-overlay"] + [
    "--extra-packages",
    "com.android.ex.chips",
] + [
    "--extra-packages",
    "com.android.colorpicker",
] + [
    "--extra-packages",
    "com.android.timezonepicker",
],

==================================================

mk:
LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.legacy_legacy-support-v13 \
    androidx.legacy_legacy-support-v4 \
    androidx.core_core
bp:
static_libs: [
    "androidx.legacy_legacy-support-v13",
    "androidx.legacy_legacy-support-v4",
    "androidx.core_core",
],

==================================================

mk:
LOCAL_STATIC_JAVA_LIBRARIES := android-ex-camera2-portability
LOCAL_STATIC_JAVA_LIBRARIES += xmp_toolkit
LOCAL_STATIC_JAVA_LIBRARIES += glide
LOCAL_STATIC_JAVA_LIBRARIES += guava
LOCAL_STATIC_JAVA_LIBRARIES += jsr305

bp:
static_libs: ["android-ex-camera2-portability"] + ["xmp_toolkit"] + ["glide"] + ["guava"] + ["jsr305"],

==================================================

mk:
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES += $(call all-java-files-under, src_pd)
LOCAL_SRC_FILES += $(call all-java-files-under, src_pd_gcam)
bp:
srcs: ["src/**/*.java"] + ["src_pd/**/*.java"] + ["src_pd_gcam/**/*.java"],

==================================================

mk:
LOCAL_RESOURCE_DIR += \
    $(LOCAL_PATH)/res \
    $(LOCAL_PATH)/res_p
bp:
resource_dirs: [
    "res",
    "res_p",
],

==================================================

mk:
LOCAL_AAPT_FLAGS := \
        --auto-add-overlay \
        --version-name "$(version_name_package)" \
        --version-code $(version_code_package) \
bp:
aaptflags: [
    "--auto-add-overlay",
    "--version-name",
    "\"" + version_name_package + "\"",
    "--version-code",
] + version_code_package,

==================================================
# 使用SDK的hide的api
LOCAL_PRIVATE_PLATFORM_APIS := true ->     platform_apis: true,
==================================================
LOCAL_CERTIFICATE := platform ->     certificate: "platform",
==================================================
LOCAL_JAVA_LIBRARIES += org.apache.http.legacy ->     libs: ["org.apache.http.legacy"],
==================================================
mk:
LOCAL_JNI_SHARED_LIBRARIES := libjni_tinyplanet libjni_jpegutil 
dp:
jni_libs: [
    "libjni_tinyplanet",
    "libjni_jpegutil",
],
==================================================
mk:
    # 声明用到的注解
LOCAL_ANNOTATION_PROCESSORS := \
    auto_value_plugin \
    javapoet-prebuilt-jar \
    dialer-dagger2 \
    dialer-dagger2-compiler \
    dialer-dagger2-producers \
    dialer-glide-annotation \
    dialer-glide-compiler \
    dialer-guava \
    dialer-javax-annotation-api \
    dialer-javax-inject \
    dialer-rootcomponentprocessor
bp:
    plugins: [
    "auto_value_plugin",
    "javapoet-prebuilt-jar",
    "dialer-dagger2",
    "dialer-dagger2-compiler",
    "dialer-dagger2-producers",
    "dialer-glide-annotation",
    "dialer-glide-compiler",
    "dialer-guava",
    "dialer-javax-annotation-api",
    "dialer-javax-inject",
    "dialer-rootcomponentprocessor",
],
==================================================
LOCAL_OVERRIDES_PACKAGES := Calculator ->     overrides: ["Calculator"],
==================================================
LOCAL_MIN_SDK_VERSION := 26 ->     min_sdk_version: "26",
==================================================
LOCAL_PRIVILEGED_MODULE := true ->     privileged: true,
==================================================
LOCAL_SYSTEM_EXT_MODULE := true ->     system_ext_specific: true,
==================================================
mk:
LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3 Launcher3QuickStep
bp:
overrides: [
    "Home",
    "Launcher2",
    "Launcher3",
    "Launcher3QuickStep",
],
==================================================
LOCAL_REQUIRED_MODULES := privapp_whitelist_com.android.launcher3 ->     required: ["privapp_whitelist_com.android.launcher3"],
==================================================
mk:
LOCAL_FULL_LIBS_MANIFEST_FILES := \
    $(LOCAL_PATH)/AndroidManifest.xml \
    $(LOCAL_PATH)/AndroidManifest-common.xml
bp:
additional_manifests: [
    LOCAL_PATH + "/AndroidManifest.xml",
    LOCAL_PATH + "/AndroidManifest-common.xml",
],
==================================================
LOCAL_MANIFEST_FILE := go/AndroidManifest.xml ->     manifest: "go/AndroidManifest.xml",
==================================================
mk:
# 混淆配置,默认为full obfuscation,全代码混淆,disabled不开启
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_PROGUARD_ENABLED := full obfuscation

dp:
optimize: {
    enabled: false,
},
==================================================
mk:
LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT_APPS)
bp:
local_module_path: {
    var: "TARGET_OUT_PRODUCT_APPS",
},
==================================================
LOCAL_COMPATIBILITY_SUITE := general-tests ->     test_suites: ["general-tests"],
==================================================
mk:
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
    contextualcards:libs/contextualcards.aar
include $(BUILD_MULTI_PREBUILT)
bp:
android_library_import {
    name: "contextualcards",
    aars: ["libs/contextualcards.aar"],
}
【5】函数宏
LOCAL_PATH := $(call my-dir):返回Android.mk 的目录
include $(call all-java-files-under,<name>):返回位于<name>目录下的所有java文件。
    如果不指定<name>,怎么返回my-dir目录下所有的java文件。
include $(call all-makefiles-under,<name>):返回位于当前 <name> 路径下所有目录中的 Android.mk 文件列表。
    利用此函数,可以为构建系统提供深度嵌套的源目录层次结构。
    默认情况下,系统只在 Android.mk 文件所在的目录中查找文件。
LOCAL_SRC_FILES := $(call all-logtags-files-under, src):返回 src 路径下所有 logtags 格式的文件。
【6】未找到对应关系
LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
LOCAL_LICENSE_CONDITIONS := notice
===========================================
# 开启AAPT2打包APK,AAPT是Android Asset Packaging Tool的缩写,AAPT2在AAPT的基础做了优化。
LOCAL_USE_AAPT2 := true
===========================================
# 在什么类型的版本下编译
# user/debug/eng: 指定该模块只在 user 版本下才编译(makePRODUCT-XXX-user)
# optional: 在所有版本下都会编译
LOCAL_MODULE_TAGS := optional
===========================================
引入aar:
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := contextualcards:libs/contextualcards.aar
include $(BUILD_MULTI_PREBUILT)
===========================================
# 声明 mk 要使用到的共享 JNI 库的名称
LOCAL_JNI_SHARED_LIBRARIES := libbluetooth_jni
===========================================
mk:
# 声明用到的注解器
LOCAL_ANNOTATION_PROCESSOR_CLASSES := \
    androidx.room.RoomProcessor
===========================================
# protocol 相关配置
LOCAL_PROTOC_OPTIMIZE_TYPE
===========================================
Android.mk 最后一句:include $(call all-makefiles-under, $(LOCAL_PATH))

[本章完...]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,098评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,213评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,960评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,519评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,512评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,533评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,914评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,574评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,804评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,563评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,644评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,350评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,933评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,908评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,146评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,847评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,361评论 2 342

推荐阅读更多精彩内容