AOSP 预编译

本文详细介绍了Android系统中蓝牙模块的预编译过程,包括动态库、静态库及运行库的生成方式与位置,同时提供了Android.bp和Android.mk两种预编译方法的示例,适合Android开发者深入了解蓝牙模块的构建流程。

Android.bp 支持的预编译

以Bluetooth为例子,其中
动态库 : android.hardware.bluetooth@1.0-impl
静态库 :android.hardware.bluetooth-async android.hardware.bluetooth-hci
运行库 :android.hardware.bluetooth@1.0-service
先进行正常编译。

//
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

cc_library_shared {
    name: "android.hardware.bluetooth@1.0-impl",
    defaults: ["hidl_defaults"],
    vendor: true,
    relative_install_path: "hw",
    srcs: [
        "bluetooth_hci.cc",
        "bluetooth_address.cc",
        "vendor_interface.cc",
    ],
    shared_libs: [
        "android.hardware.bluetooth@1.0",
        "libbase",
        "libcutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "liblog",
        "libutils",
    ],
    static_libs: [
        "android.hardware.bluetooth-async",
        "android.hardware.bluetooth-hci",
    ],
}

cc_library_static {
    name: "android.hardware.bluetooth-async",
    vendor: true,
    defaults: ["hidl_defaults"],
    srcs: [
        "async_fd_watcher.cc",
    ],
    export_include_dirs: ["."],
    shared_libs: [
        "liblog",
    ],
}

cc_library_static {
    name: "android.hardware.bluetooth-hci",
    vendor: true,
    defaults: ["hidl_defaults"],
    srcs: [
        "hci_packetizer.cc",
        "hci_protocol.cc",
        "h4_protocol.cc",
        "mct_protocol.cc",
    ],
    export_include_dirs: ["."],
    shared_libs: [
        "libbase",
        "libhidlbase",
        "liblog",
        "libutils",
    ],
}

cc_test {
    name: "bluetooth-vendor-interface-unit-tests",
    vendor: true,
    defaults: ["hidl_defaults"],
    srcs: [
        "test/async_fd_watcher_unittest.cc",
        "test/h4_protocol_unittest.cc",
        "test/mct_protocol_unittest.cc",
    ],
    local_include_dirs: [
        "test",
    ],
    shared_libs: [
        "libbase",
        "libhidlbase",
        "liblog",
        "libutils",
    ],
    static_libs: [
        "android.hardware.bluetooth-async",
        "android.hardware.bluetooth-hci",
        "libgmock",
    ],
}

cc_test_host {
    name: "bluetooth-address-unit-tests",
    defaults: ["hidl_defaults"],
    srcs: [
        "bluetooth_address.cc",
        "test/bluetooth_address_test.cc",
        "test/properties.cc",
    ],
    local_include_dirs: [
        "test",
    ],
    shared_libs: [
        "libbase",
        "liblog",
    ],
}

cc_binary {
    name: "android.hardware.bluetooth@1.0-service",
    defaults: ["hidl_defaults"],
    relative_install_path: "hw",
    vendor: true,
    init_rc: ["android.hardware.bluetooth@1.0-service.rc"],
    srcs: ["service.cpp"],

    shared_libs: [
        "liblog",
        "libcutils",
        "libdl",
        "libbase",
        "libutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "android.hardware.bluetooth@1.0",
    ],
}

动态库生成位置:out/target/product/(PRODUCT_NAME)/obj(obj_arm)/SHARED_LIBRARIES/
静态库生成位置:out/target/product/(PRODUCT_NAME)/obj(obj_arm)/STATIC_LIBRARIES/
其中obj是64位,obj_arm是32位。也可以用以下命令进行确认。
静态库:

objdump -a abc.a

动态库:

file abc.so
预编译

Android.bp 支持五种预编译,如下:

var prebuiltTypes = map[string]string{
        "SHARED_LIBRARIES": "cc_prebuilt_library_shared",
        "STATIC_LIBRARIES": "cc_prebuilt_library_static",
        "EXECUTABLES":      "cc_prebuilt_binary",
        "JAVA_LIBRARIES":   "java_import",
        "ETC":              "prebuilt_etc",
}

预编译的文件如下:

cc_prebuilt_library_shared {
    name: "android.hardware.bluetooth@1.0-impl",
    vendor: true,
    relative_install_path: "hw",
    multilib: {
        lib64: {
            srcs: ["lib64/android.hardware.bluetooth@1.0-impl.so"],
        },
        lib32: {
            srcs: ["lib/android.hardware.bluetooth@1.0-impl.so"],
        },
    },
    
    strip: {
        none:true,
    },
    compile_multilib:"both",
}

cc_prebuilt_library_static {
    name: "android.hardware.bluetooth-async",
    vendor: true,
    export_include_dirs: ["."],
    multilib: {
        lib64: {
            srcs: ["lib64/android.hardware.bluetooth-async.a"],
        },
        lib32: {
            srcs: ["lib/android.hardware.bluetooth-async.a"],
        },
    },
    
    strip: {
        none:true,
    },
    compile_multilib:"both",
}

cc_prebuilt_library_static {
    name: "android.hardware.bluetooth-hci",
    vendor: true,
    export_include_dirs: ["."],
    multilib: {
        lib64: {
            srcs: ["lib64/android.hardware.bluetooth-hci.a"],
        },
        lib32: {
            srcs: ["lib/android.hardware.bluetooth-hci.a"],
        },
    },
    
    strip: {
        none:true,
    },
    compile_multilib:"both",
}

cc_prebuilt_binary {
    name: "android.hardware.bluetooth@1.0-service",
    relative_install_path: "hw",
    vendor: true,
    srcs:["android.hardware.bluetooth@1.0-service"],
    init_rc: ["android.hardware.bluetooth@1.0-service.rc"],
    strip: {
        none:true,
    },
}

Android.mk 预编译

因为有些时候 bp文件无法引用mk定义的 module,所以只能用mk去引用mk。

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.wifi@1.0-service-lib
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TAGS   := optional
LOCAL_MODULE_CLASS  := STATIC_LIBRARIES   //预编译静态库
LOCAL_MODULE_SUFFIX := .a
LOCAL_MULTILIB      := 64
LOCAL_SRC_FILES := \
    vendor/lib64/android.hardware.wifi@1.0-service-lib.a
LOCAL_SHARED_LIBRARIES := \
    libbase \
    libcutils \
    libhidlbase \
    libhidltransport \
    liblog \
    libnl \
    libutils \
    libwifi-hal \
    libwifi-system-iface \
    android.hardware.wifi@1.0 \
    android.hardware.wifi@1.1 \
    android.hardware.wifi@1.2
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
include $(BUILD_PREBUILT)

###
### android.hardware.wifi daemon
###
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.wifi@1.0-service
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TAGS  := optional
LOCAL_MODULE_CLASS := EXECUTABLES    //预编译可执行文件
LOCAL_SRC_FILES := \
    vendor/bin/android.hardware.wifi@1.0-service
LOCAL_SHARED_LIBRARIES := \
    libbase \
    libcutils \
    libhidlbase \
    libhidltransport \
    liblog \
    libnl \
    libutils \
    libwifi-hal \
    libwifi-system-iface \
    android.hardware.wifi@1.0 \
    android.hardware.wifi@1.1 \
    android.hardware.wifi@1.2
LOCAL_STATIC_LIBRARIES := \
    android.hardware.wifi@1.0-service-lib
LOCAL_INIT_RC := android.hardware.wifi@1.0-service.rc
include $(BUILD_PREBUILT)


include $(CLEAR_VARS)
LOCAL_MODULE        :=  com.qualcomm.qti.dpm.api@1.0_system
LOCAL_INSTALLED_MODULE_STEM := com.qualcomm.qti.dpm.api@1.0.so
LOCAL_MODULE_CLASS  := SHARED_LIBRARIES   //预编译动态库
LOCAL_MODULE_SUFFIX := .so
LOCAL_STRIP_MODULE  := false
LOCAL_MULTILIB      := 64
LOCAL_MODULE_OWNER  := qcom
LOCAL_MODULE_TAGS   := optional
LOCAL_SRC_FILES     := ../../.././target/product/msmnile_gvmq/system/lib64/com.qualcomm.qti.dpm.api@1.0.so
LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/lib64
include $(BUILD_PREBUILT)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值