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))
[本章完...]
网友评论