自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
設定共用程式庫
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
建立音訊政策設定後,您必須將 HAL 實作項目封裝至共用程式庫,並複製至適當位置:
- 建立
device/<company>/<device>/audio
目錄,用於容納程式庫的來源檔案。
- 建立
Android.mk
檔案來建構共用程式庫。確認 Makefile 包含下列程式碼行:
LOCAL_MODULE := audio.primary.<device>
您的程式庫必須命名為 audio.primary.<device>.so
,才能讓 Android 正確載入程式庫。檔案名稱中的 primary
部分表示這個共用程式庫適用於裝置上的主要音訊硬體。藍牙和 USB 音訊介面也適用於模組名稱 audio.a2dp.<device>
和 audio.usb.<device>
。以下是 Galaxy Nexus 音訊硬體的 Android.mk
範例:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := audio.primary.tuna
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := audio_hw.c ril_interface.c
LOCAL_C_INCLUDES += \
external/tinyalsa/include \
$(call include-path-for, audio-utils) \
$(call include-path-for, audio-effects)
LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libdl
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
- 如果產品支援 Android CDD 指定的低延遲音訊,請將對應的 XML 功能檔案複製到產品中。例如,在產品的
device/<company>/<device>/device.mk
Makefile 中:
PRODUCT_COPY_FILES := ...
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.audio.low_latency.xml:system/etc/permissions/android.hardware.audio.low_latency.xml \
- 將先前建立的音訊政策設定檔複製到產品
device/<company>/<device>/device.mk
Makefile 中的 system/etc/
目錄。例如:
PRODUCT_COPY_FILES += \
device/samsung/tuna/audio/audio_policy.conf:system/etc/audio_policy.conf
- 在產品的
device/<company>/<device>/device.mk
Makefile 中,宣告產品所需的音訊 HAL 共用模組。舉例來說,Galaxy Nexus 需要主要和藍牙音訊 HAL 模組:
PRODUCT_PACKAGES += \
audio.primary.tuna \
audio.a2dp.default
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-03-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-03-26 (世界標準時間)。"],[],[],null,["# Configure a shared library\n\nAfter creating an\n[audio policy\nconfiguration](/docs/core/audio/implement-policy), you must package the HAL implementation into a shared library\nand copy it to the appropriate location:\n\n1. Create a `device/\u003ccompany\u003e/\u003cdevice\u003e/audio` directory to contain your library's source files.\n2. Create an `Android.mk` file to build the shared library. Ensure the Makefile contains the following line: \n\n ```\n LOCAL_MODULE := audio.primary.\u003cdevice\u003e\n ```\n\n Your library must be named `audio.primary.\u003cdevice\u003e.so`\n so Android can correctly load the library. The `primary` portion of\n this filename indicates that this shared library is for the primary audio\n hardware located on the device. The module names\n `audio.a2dp.\u003cdevice\u003e` and\n `audio.usb.\u003cdevice\u003e` are also available for Bluetooth and\n USB audio interfaces. Here is an example of an `Android.mk` from the\n Galaxy Nexus audio hardware: \n\n ```\n LOCAL_PATH := $(call my-dir)\n\n include $(CLEAR_VARS)\n\n LOCAL_MODULE := audio.primary.tuna\n LOCAL_MODULE_RELATIVE_PATH := hw\n LOCAL_SRC_FILES := audio_hw.c ril_interface.c\n LOCAL_C_INCLUDES += \\\n external/tinyalsa/include \\\n $(call include-path-for, audio-utils) \\\n $(call include-path-for, audio-effects)\n LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libdl\n LOCAL_MODULE_TAGS := optional\n\n include $(BUILD_SHARED_LIBRARY)\n ```\n\n3. If your product supports low latency audio as specified by the Android CDD, copy the corresponding XML feature file into your product. For example, in your product's `device/\u003ccompany\u003e/\u003cdevice\u003e/device.mk` Makefile: \n\n ```\n PRODUCT_COPY_FILES := ...\n\n PRODUCT_COPY_FILES += \\\n frameworks/native/data/etc/android.hardware.audio.low_latency.xml:system/etc/permissions/android.hardware.audio.low_latency.xml \\\n ```\n\n4. Copy the audio policy configuration file you created earlier to the `system/etc/` directory in your product's `device/\u003ccompany\u003e/\u003cdevice\u003e/device.mk` Makefile. For example: \n\n ```\n PRODUCT_COPY_FILES += \\\n device/samsung/tuna/audio/audio_policy.conf:system/etc/audio_policy.conf\n ```\n\n5. Declare the shared modules of your audio HAL that are required by your product in the product's `device/\u003ccompany\u003e/\u003cdevice\u003e/device.mk` Makefile. For example, the Galaxy Nexus requires the primary and Bluetooth audio HAL modules: \n\n ```\n PRODUCT_PACKAGES += \\\n audio.primary.tuna \\\n audio.a2dp.default\n ```"]]