Skip to content
  • English
  • Polski
Digital Karabela
Digital Karabela
Primary Navigation Menu
Menu
  • Home
  • Products
  • DevBlog
  • Castle Engine
  • About

How to compile OpenAL library for Android with Oboe library.

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 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=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 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=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 🙂

2023-07-01
On July 1, 2023
In Castle Game Engine, DevBlog, Programming
Tagged android, castleengine, gamedev, mobiledev
Previous Post: Lazarus 2.0.12 Released

Try my new game! Free to play!

Logo Bricks Color Pick

Bricks Color Pick is a completely new approach to classic Arkanoid! No paddle! Now your goal is to switch the color of the ball to the color of the brick.

Get it from Google Play

Level 37/40 5-6 Colors Screenshot

You can also change ball movement direction by the button in top left corner.

QR Code Google Play Bricks Color Pick

Level 62/80 (RelaxMode) Screenshot

Recent Posts

  • How to compile OpenAL library for Android with Oboe library.
  • Lazarus 2.0.12 Released
  • How to Fix LMMS GUI Freezing on Linux?
  • How to update wine to 5.0.0 on Linux Mint 19 or Ubuntu 18?
  • Agile Commander 1.2.3 Released!

Categories

  • DevBlog
  • GameDev
    • Castle Game Engine
    • Godot Engine
  • Linux
  • Programming
    • Dlang
      • DlangUI
    • Object Pascal
      • Lazarus
  • Promotion

Products:
Agile Commander
Bricks Color Pick

 

 

Digital Karabela – Andrzej Kilijański
76-015 Wyszebórz 32, Poland
https://digitalkarabela.com
Contact
Privacy Policy