將 Oboe 程式庫納入專案的方法有兩種。
將 Oboe 與 Gradle 和 CMake 整合
這些操作說明僅適用於搭配 CMake 原生依附元件並使用 Android Gradle 外掛程式 4.1.0 以上版本的專案。
如果專案使用的是 Android Gradle 外掛程式 4.0 或 ndk-build 而非 CMake,流程會稍微不同。請參閱使用原生依附元件一文。
更新 build.gradle
如要在使用 Android Gradle 外掛程式 4.1.0 以上版本時將 Oboe 新增至應用程式,請在應用程式的 build.gradle 檔案中新增以下程式碼。
- 將 - oboe依附元件新增至- dependencies部分。如有必要,請將- 1.5.0替換為 Oboe 的最新穩定版:- dependencies { implementation 'com.google.oboe:oboe:1.5.0' }
- 在「 - buildFeatures」部分中啟用「- prefab」選項。- android { buildFeatures { prefab true } }
- 將應用程式設為使用共用 STL: - android { defaultConfig { externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared" } } } }
更新 CMakeLists.txt
新增 Oboe 時,必須在應用程式的 CMakeLists.txt 檔案中加入兩個新增項目。
- 新增下列 - find_package指令:- find_package (oboe REQUIRED CONFIG)
- 將 - oboe::oboe新增到傳送至主要執行檔相關- target_link_libraries指令的程式庫清單。
與 Android Game SDK 整合
- 下載程式庫,並在來源控管系統中加以確認。 
- 對專案的建構設定進行下列變更。 
靜態資料庫
整合 Android Game SDK 時,您將以靜態方式連結至以特定 ABI、API 級別、NDK 和 STL 組合編譯的 Oboe 程式庫版本:
- 將 gamesdk/include新增至編譯器,其中包含路徑。
- 在連結器程式庫路徑中新增以下形式的路徑: - gamesdk/libs/architecture_APIapiLevel_NDKndkVersion_stlVersion_Release - 例如: - gamesdk/libs/arm64-v8a_API24_NDK18_cpp_static_Release
- 將 - -loboe_static加入連接器指令。
不需整合 liboboe.so 共用資料庫,表示靜態連結將提供較少的程式碼量。
共用資料庫
如果設定無法支援靜態資料庫所需的 ABI、API 級別、NDK 和 STL 組合,可以改為連結至共用資料庫。
- 請按照前一個工作階段 (關於靜態資料庫) 的步驟 1 和 2,更新編譯器包含路徑,並使用適當的標頭檔案。 
- 在連結器程式庫路徑中新增以下形式的路徑: - gamesdk/libs/architectureAPIapiLevelNDKndkVersion_stlVersion_Release/lib/oboe 
- Add - -loboe -lOpenSLESto your linker command.
Using CMake (static library only)
If you're using CMake, see the gamesdk/samples/bouncyball/app/CMakeLists.txt
file in the downloaded SDK for an example CMake configuration. It includes a
utility file called gamesdk/samples/gamesdk.cmake, which performs final
checks, adds the proper compiler include paths, and generates a target that you
can use to link the library.
To use the gamesdk.cmake utility:
- Include this file in your - CMakeLists.txt:- // Use a relative or absolute path. For example, /home/yourusername/gamesdk // or C:\Android\gamesdk. - include("path/to/gamesdk/samples/gamesdk.cmake")
- 如要呼叫 - add_gamesdk_target函式,請使用包含 gamesdk 的資料夾:- // Use a relative or absolute path. - add_gamesdk_target(PACKAGE_DIR path/to/gamesdk)
- 在原生資料庫的 - target_link_libraries中,將- oboe新增為依附元件:- // The casing of OpenSLES is important. - target_link_libraries(native-lib oboe OpenSLES ...)
如需 CMake 的進階用法,請參閱 gamesdk.cmake 來源檔案。
後續步驟:使用 Oboe
如要使用 Oboe 播放或錄製音訊,請建立並啟用一或多個音訊串流,並使用回呼在音訊輸入/輸出裝置和應用程式之間交換音訊。參閱使用 Oboe 一文。
