Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

在 Android 中編譯 alsa-utils 工具的完整流程

編輯:關於 Android 程式設計

近來在研究 ALSA 的 driver,並嘗試於 Android 環境中編譯 alsa-utils 工具。以下把整個編譯過程以及期間遇到的問題與解法記錄下來,供需要的朋友參考。

版本選擇與放置

首先從 ALSA 官方網站下載 alsa-utils-1.0.23 版本的工具。由於專案中的 alsa-lib 也是 1.0.23 版,為了避免版本不一致而衍生問題,特別選擇相同版本。alsa-lib 位於 android_source/external/alsa-lib 目錄下,因此也把下載的 alsa-utils-1.0.23 放到同一個位置。

步驟一:建立 Android.mk

在 alsa-utils 目錄下建立 Android.mk,內容如下(此處僅示範編譯 aplay,其他工具寫法相同):

ifeq ($(strip $(BOARD_USES_ALSA_AUDIO)),true)

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_CFLAGS := \
    -fPIC -D_POSIX_SOURCE \
    -DALSA_CONFIG_DIR=\"/system/usr/share/alsa\" \
    -DALSA_PLUGIN_DIR=\"/system/usr/lib/alsa-lib\" \
    -DALSA_DEVICE_DIRECTORY=\"/dev/snd/\"

LOCAL_C_INCLUDES:= \
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/android \
    external/alsa-lib/include

LOCAL_SRC_FILES := \
    aplay/aplay.c

LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := alsa_aplay
LOCAL_SHARED_LIBRARIES := \
    libasound \
    libc
include $(BUILD_EXECUTABLE)

步驟二:建立 sys 目錄與 aconfig.h

接著在 alsa-utils 工具包中建立 sys 目錄與 aconfig.h 檔,並在其中寫入以下內容:

#define DATADIR "/system/usr/share/alsa"

#define rindex strrchr

#define open64 open

#undef __swab16
#define __swab16(x)  __arch__swab16((x))

#undef __swab32
#define __swab32(x)  __arch__swab32((x))

步驟三:建立 signal.h

進入上一步建立的 sys 目錄,建立 signal.h 頭檔,內容為:

#include <signal.h>

步驟四:編譯並排除常見錯誤

完成以上設定後即可直接編譯 Android。過程中可能遇到以下幾個錯誤:

4.1 出現 linux/un.h:18: error: expected specifier-qualifier-list before 'sa_family_t':這是因為 alsa-utils/alsactl/init_parse.c 在 include un.h 之前沒有先 include <sys/socket.h>,於該處補上即可解決。

4.2 出現 aplay.c ... 'S_IRGRP' undeclared:只要在 aplay.c 中加上 #include <sys/stat.h> 便可解決。

4.3 出現 speaker-test.c ... wav_file_dir 沒有定義:這個值用來指定 wav 檔案在裝置中的存放位置,可自訂任意路徑,本例中定義在 /sdcard 目錄下。

經過上述種種修改後,alsa-utils 工具終於能順利編譯成功。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved