欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android 10 根文件系统和编译系统(十九):Android.bp各种模块编译规则

程序员文章站 2022-03-11 16:09:31
...

 配套系列教学视频链接:

      安卓系列教程之ROM系统开发-百问100ask


说明

系统:AOSP Android10.0

设备:Android x86模拟器

前言

    了解完了Android.bp的语法之后,  本章节重点介绍Android.bp各种模块的编译规则写法, Andorid.bp编写好之后, 依然可以通过mmm来编译


一, 可执行程序

模板: system/core/reboot/Android.bp

cc_binary {
    name: "reboot",
    srcs: ["reboot.c"],
    shared_libs: ["libcutils"],
    cflags: ["-Werror"],
}

二,动态库编译

模板: frameworks/av/camera/Android.bp

cc_library_shared { //编译成动态库,类似于Android.mk中的BUILD_SHARED_LIBRARY
    name: "libcamera_client",
    aidl: {
        export_aidl_headers: true,  //是否导出aidl头文件路径
        local_include_dirs: ["aidl"], //将[指定的目录列表]加入aidl 搜索头文件路径。
// [“aidl”]表示当前目录下的aidl目录
        include_dirs: [ //指定搜索外部aidl头文件的路径
            "frameworks/native/aidl/gui",
        ],
    },
    srcs: [ //源文件,类似于Android.mk中的LOCAL_SRC_FILES
        // AIDL files for camera interfaces
        // The headers for these interfaces will be available to any modules that
        // include libcamera_client, at the path "aidl/package/path/BnFoo.h"
        ":libcamera_client_aidl", //引用了另外一个模块中定义的源文件。在当前bp文件的第81行

        // Source for camera interface parcelables, and manually-written interfaces
        "Camera.cpp",
        "CameraMetadata.cpp",
        "CameraParameters.cpp",
        "CaptureResult.cpp",
        "CameraParameters2.cpp",
        "ICamera.cpp",
        "ICameraClient.cpp",
        "ICameraRecordingProxy.cpp",
        "ICameraRecordingProxyListener.cpp",
        "camera2/CaptureRequest.cpp",
        "camera2/OutputConfiguration.cpp",
        "camera2/SessionConfiguration.cpp",
        "camera2/SubmitInfo.cpp",
        "CameraBase.cpp",
        "CameraUtils.cpp",
        "VendorTagDescriptor.cpp",
    ],

    shared_libs: [ //编译所依赖的动态库,类似于Android.mk中的LOCAL_SHARED_LIBRARIES
        "libcutils",
        "libutils",
        "liblog",
        "libbinder",
        "libgui",
        "libcamera_metadata",
        "libnativewindow",
    ],

    include_dirs: [//用户指定的头文件查找路径,类似于Android.mk中的LOCAL_C_INCLUDES
        "system/media/private/camera/include",
        "frameworks/native/include/media/openmax",
    ],
    export_include_dirs: [//将当前的路径导出,如果有其他模块引用当前模块,就不需要指定头文件路径
         "include",
         "include/camera"
    ],
    export_shared_lib_headers: ["libcamera_metadata"],//将libcamera_metadata模块对应的头文件路径列表导出

    cflags: [//编译flag,类似于Android.mk中的LOCAL_CFLAGS
        "-Werror",
        "-Wall",
        "-Wextra",
    ],
}

三, java动态库-JAR包

Java静态库模板:frameworks/base/services/usage/Android.bp

java_library_static {
    name: "services.usage",
    srcs: ["java/**/*.java"],
   libs: ["services.core"], //链接的动态库-./frameworks/base/services/core/Android.bp定义,
   //对应的库会生成在out/soong/.intermediates/frameworks/base/services/core/services.core
}

四,编译APK

Android9.0的源码中比较少用Android.bp来编译apk, 到了10之后就大量使用了Android.bp,参考模板:

packages/apps/Music/Android.bp

packages/apps/QuickSearchBox/Android.bp

android_app {
    name: "Music",
    srcs: [
        "src/**/*.java",
        "src/com/android/music/IMediaPlaybackService.aidl",
    ],
    sdk_version: "current",
    product_specific: true, //安装到product分区
    optimize: {
        proguard_flags_files: ["proguard.flags"],
    },
    certificate: "platform",
}

其他参考: packages/apps/Nfc/Android.bp