While testing my Bricks Color Pick game on a new Android 13 device, I noticed a strange sound issue. Increasing the data buffer size did not help. The solution is to recompile the OpenAL library with the Oboe library. OpenAL is the default audio backend for the Castle Game Engine.
I use Linux Mint 21, but the procedure itself should also be helpful if you’re using Windows or MacOS. I assume you have Android Studio with NDK, make and git installed.
Source Download
We need to download two repositories:
- openal-soft – https://github.com/kcat/openal-soft
- oboe – https://github.com/google/oboe
First, we create a folder for sources:
mkdir openal
Then we download openal-soft:
git clone https://github.com/kcat/openal-soft.git
After downloading the sources, select the last stable tag, e.g. 1.23.1:
cd openal-soft git checkout 1.23.1 cd ..
Next we download oboe – without this framework sound on android doesn’t work very well.
git clone https://github.com/google/oboe.git
After downloading, set a stable tag, e.g. 1.7.0.
cd oboe git checkout 1.7.0 cd ..
OK now it’s time to set the environment.
Environment Variables
We need to have the NDK installed (I use 22.1.7171670 version) and set the NDK_ROOT auxiliary environment variable. The path on your system will obviously be different:
export NDK_ROOT=/home/and3md/android/sdk/ndk/22.1.7171670
Preparation for compilation
We will have to do builds for all supported architectures the most important are:
- armeabi-v7a
- arm64-v8a
- x86
- x86_64
Each of the architectures and each version of the NDK may require/support a different minimum API level, e.g. NDK 22 in my case has minimum supported API levels:
- armeabi-v7a – 16
- arm64-v8a
-
22
We will set the API level using ANDROID_PLATFORM, and the architecture itself using ANDROID_ABI, e.g.:
-DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=16
STL Selection
If we only have one library in the project, we can use c++_static. If we use more libraries, c++_shared is recommended. More info: https://developer.android.com/ndk/guides/cpp-support#static_runtimes
Oboe source folder
We set the it in OBOE_SOURCE parameter like that:
-DOBOE_SOURCE=/home/and3md/fpc/openal/oboe
cmake setup and build
First we go to the openal-soft/build
folder.
For armeabi-v7a architecture
We run the cmake
command to generate the makefile:
cmake .. -DANDROID_STL=c++_shared -DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=armeabi-v7a -DOBOE_SOURCE=../oboe -DANDROID_PLATFORM=16
next we start the compilation:
make
We copy the resulting libopenal.so file, because we will use the sources to compile library for the next architecture.
For arm64-v8a architecture
We clean the sources
make clean
We run the cmake
command to generate the makefile:
cmake .. -DANDROID_STL=c++_shared -DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=arm64-v8a -DOBOE_SOURCE=../oboe -DANDROID_PLATFORM=22
next we start the compilation:
make
Copy the resulting libopenal.so file.
For x86 architecture
We clean the sources
make clean
We run the cmak
e command to generate the makefile:
cmake .. -DANDROID_STL=c++_shared -DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=x86 -DOBOE_SOURCE=../oboe -DANDROID_PLATFORM=16
next we start the compilation:
make
Copy the resulting libopenal.so file.
For x86_64 architecture
We clean the sources
make clean
We run the cmak
e command to generate the makefile:
cmake .. -DANDROID_STL=c++_shared -DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=x86_64 -DOBOE_SOURCE=../oboe -DANDROID_PLATFORM=16
next we start the compilation:
make
Copy the resulting libopenal.so file.
Library files size reduction
Generated files can be very large (about 15 MB). We can reduce their size by running the strip
command from the appropriate architecture:
${NDK_ROOT}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/strip libopenal.so ${NDK_ROOT}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip libopenal.so ${NDK_ROOT}/toolchains/x86-4.9/prebuilt/linux-x86_64/i686-linux-android/bin/strip libopenal.so ${NDK_ROOT}/toolchains/x86_64-4.9/prebuilt/linux-x86_64/x86_64-linux-android/bin/strip libopenal.so
And that’s all 🙂