介绍
Android.bp的出现就是为了替换Android.mk文件。bp跟mk文件不同,它是纯粹的配置,没有分支、循环等流程控制,不能做算数逻辑运算。如果需要控制逻辑,那么只能通过Go语言编写。说明
cc_library_shared :编译成动态库,类似于Android.mk中的BUILD_SHARED_LIBRARY cc_binary:编译成可执行文件,类似于Android.mk中的BUILD_EXECUTABLE name :编译出的模块的名称,类似于Android.mk中的LOCAL_MODULE srcs:源文件,类似于Android.mk中的LOCAL_SRC_FILES include_dirs:用户指定的头文件查找路径,类似于Android.mk中的LOCAL_C_INCLUDES local_include_dirs:指定路径查找头文件,类似于Android.mk中的LOCAL_C_INCLUDES shared_libs:编译所依赖的动态库,类似于Android.mk中的LOCAL_SHARED_LIBRARIES static_libs:编译所依赖的静态库,类似于Android.mk中的LOCAL_STATIC_LIBRARIES cflags:编译flag,类似于Android.mk中的LOCAL_CFLAGS注释
Android.bp使用单行注释//和多行注释/* */两种方式。模块
Android.bp可以支持android_app、cc_binary、cc_binary_host等多种类型,具体定义在Android源码的build/soong/androidmk/cmd/androidmk/android.go可以查看,具体如下:var moduleTypes = map[string]string{ "BUILD_SHARED_LIBRARY": "cc_library_shared", "BUILD_STATIC_LIBRARY": "cc_library_static", "BUILD_HOST_SHARED_LIBRARY": "cc_library_host_shared", "BUILD_HOST_STATIC_LIBRARY": "cc_library_host_static", "BUILD_HEADER_LIBRARY": "cc_library_headers", "BUILD_EXECUTABLE": "cc_binary", "BUILD_HOST_EXECUTABLE": "cc_binary_host", "BUILD_NATIVE_TEST": "cc_test", "BUILD_HOST_NATIVE_TEST": "cc_test_host", "BUILD_NATIVE_BENCHMARK": "cc_benchmark", "BUILD_HOST_NATIVE_BENCHMARK": "cc_benchmark_host", "BUILD_JAVA_LIBRARY": "java_library", "BUILD_STATIC_JAVA_LIBRARY": "java_library_static", "BUILD_HOST_JAVA_LIBRARY": "java_library_host", "BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik", "BUILD_PACKAGE": "android_app", }模块包含一些属性格式为“property-name:property-value”,其中name属性必须指定,其属性值必须是全局唯一的。 其中默认模块可用于在多个模块中重复相同的属性,是不是用文字表达很模糊,好吗,上实例:
cc_defaults {// //默认模块名称 name: "default_module", shared_libs: ["libz"], stl: "none", } cc_binary { name: "test1", defaults: ["default_module"], //引用默认模块名称 srcs: ["src/test/test.c"], }srcs 属性以字符串列表的形式指定用于编译模块的源文件。您可以使用模块引用语法 “:” 来引用生成源文件的其他模块的输出,如 genrule 或 filegroup。是不是感觉一头雾水,好吗,还是上实例说明:
~/ssd/qcom_64/msm8953-9$ cd frameworks/base/core/java/ ~/ssd/qcom_64/msm8953-9/frameworks/base/core/java$ vi Android.bp filegroup { name: "IKeyAttestationApplicationIdProvider.aidl", srcs: ["android/security/keymaster/IKeyAttestationApplicationIdProvider.aidl"], } filegroup { name: "IDropBoxManagerService.aidl", srcs: ["com/android/internal/os/IDropBoxManagerService.aidl"], ~/ssd/qcom_64/msm8953-9/frameworks/base/core$ cd .. ~/ssd/qcom_64/msm8953-9/frameworks/base$ vi libs/services/Android.bp cc_library_shared { name: "libservices", srcs: [ ":IDropBoxManagerService.aidl", "src/os/DropBoxManager.cpp", "src/os/StatsDimensionsValue.cpp", "src/os/StatsLogEventWrapper.cpp", ], shared_libs: [ "libbinder", "liblog", "libcutils", "libutils", ],
变量
我们知道Android.mk中可以定义变量,当然作为新编译系统中替代Android.mk的Android.bp也是一定存在,更加何况Android.mk还可以一定条件的转换成Android.bp。 变量范围限定为声明它们的文件的其余部分,可以使用 “=” 号赋值, 但是不能使用 “:=” 赋值。变量是不可变的,但有一个例外它们可以附上+= 赋值,但仅在变量被引用之前。gzip_srcs = ["src/minigzip.c"], cc_binary { name: "gzip", srcs: gzip_srcs, shared_libs: ["libz"], stl: "none", }
类型
具体支持以下几种类型:- Bool(true or false)
- Integers(int)
- Strings("string")
- Listsof strings (["string1", "string2"])
- Maps({key1: "value1", key2: ["value2"]})
操作符
String类型、字符串列表类型和Map类型支持操作符“+”。可以使用 + 运算符对整数求和。附加映射会生成两个映射中键的并集,并附加在两个映射中都存在的所有键的值。Strings, lists of strings, and maps can be appended using the + operator. Integers can be summed up using the + operator. Appending a map produces the union of keys in both maps, appending the values of any keys that are present in both maps.
支持预编译类型
Android.bp可以支持多种预编译类型,具体定义在Android源码的build/soong/androidmk/cmd/androidmk/android.go可以查看,如下图所示:var prebuiltTypes = map[string]string{ "SHARED_LIBRARIES": "cc_prebuilt_library_shared", "STATIC_LIBRARIES": "cc_prebuilt_library_static", "EXECUTABLES": "cc_prebuilt_binary", "JAVA_LIBRARIES": "prebuilt_java_library", }
条件式编译
system/core/libusbhost$ cat Android.bp cc_library { name: "libusbhost", vendor_available: true, vndk: { enabled: true, }, host_supported: true, srcs: ["usbhost.c"], cflags: ["-Werror"], export_include_dirs: ["include"], target: { android: { //编译Android上运行的程序 cflags: [ "-g", "-DUSE_LIBLOG", ], shared_libs: ["liblog"], }, darwin: { //编译darwin上运行的程序 enabled: false, }, }, }英:https://blog.csdn.net/manjianchao/article/details/84896838 中:https://blog.csdn.net/weixin_39890633/article/details/111485076 标签:cc,mk,bp,BUILD,Android,library From: https://www.cnblogs.com/kongbursi-2292702937/p/17215206.html