À partir du 27 mars 2025, nous vous recommandons d'utiliser android-latest-release
au lieu de aosp-main
pour créer et contribuer à AOSP. Pour en savoir plus, consultez la section Modifications apportées à AOSP.
Configurer une bibliothèque partagée
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Après avoir créé une configuration de stratégie audio, vous devez empaqueter l'implémentation HAL dans une bibliothèque partagée et la copier à l'emplacement approprié:
- Créez un répertoire
device/<company>/<device>/audio
pour contenir les fichiers sources de votre bibliothèque.
- Créez un fichier
Android.mk
pour compiler la bibliothèque partagée. Assurez-vous que le fichier Makefile contient la ligne suivante :
LOCAL_MODULE := audio.primary.<device>
Votre bibliothèque doit être nommée audio.primary.<device>.so
pour qu'Android puisse la charger correctement. La partie primary
de ce nom de fichier indique que cette bibliothèque partagée est destinée au matériel audio principal situé sur l'appareil. Les noms de module audio.a2dp.<device>
et audio.usb.<device>
sont également disponibles pour les interfaces audio Bluetooth et USB. Voici un exemple d'Android.mk
du matériel audio du Galaxy Nexus:
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)
- Si votre produit est compatible avec l'audio à faible latence, comme spécifié par le CDD Android, copiez le fichier de fonctionnalités XML correspondant dans votre produit. Par exemple, dans le fichier Makefile
device/<company>/<device>/device.mk
de votre produit:
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 \
- Copiez le fichier de configuration des règles audio que vous avez créé précédemment dans le répertoire
system/etc/
du fichier Makefile device/<company>/<device>/device.mk
de votre produit.
Exemple :
PRODUCT_COPY_FILES += \
device/samsung/tuna/audio/audio_policy.conf:system/etc/audio_policy.conf
- Déclarez les modules partagés de votre HAL audio requis par votre produit dans le fichier Makefile
device/<company>/<device>/device.mk
du produit.
Par exemple, le Galaxy Nexus nécessite les modules HAL audio principaux et Bluetooth:
PRODUCT_PACKAGES += \
audio.primary.tuna \
audio.a2dp.default
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/03/26 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/03/26 (UTC)."],[],[],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 ```"]]