raylib: [raudio] Makefile not setting the appropriate macros to enable audio on Android
When working in Android and compiling Raylib from source, the audio backend is detected as NULL and the app remains silent despite sound/music being loaded correctly, as InitAudioDevice()
logs:
AUDIO: Device initialized successfully
> Backend: miniaudio / Null
> Format: 32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
> Channels: 2 -> 2
> Sample rate: 48000 -> 48000
> Periods size: 1440
After some testing I discovered that miniaudio.h
requires to set the macros MA_SUPPORT_AAUDIO
and MA_ENABLE_AAUDIO
to enable audio when compiling for Android.
None of them are set neither in the Makefile or in raudio.c
so default builds for Android have the audio disabled. Setting both macros is enough to enable audio in Android.
Tested on Linux
Host OS: Solus Linux Android NDK: 23.1.7779620 Target SDK: 31 Android Studio: 2020.3.1 Patch 2 CMake : v3.18.1 (Bundled with Android Studio)
Compiled from source for Android with the following line
make raylib PLATFORM=PLATFORM_ANDROID RAYLIB_BUILD_MODE=DEBUG RAYLIB_LIBTYPE=STATIC ANDROID_ARCH=ARM64 ANDROID_API=31
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 26 (13 by maintainers)
Commits related to this issue
- Try improving Android detection. Issue from raylib: https://github.com/raysan5/raylib/issues/2118 — committed to mackron/miniaudio by mackron 2 years ago
- Fix android sound issue #2118 — committed to planetis-m/raylib by planetis-m a year ago
- Fix android sound issue #2118 (#2875) — committed to raysan5/raylib by planetis-m a year ago
- Fix android sound issue #2118 (#2875) — committed to futureapricot/raylib by planetis-m a year ago
Thanks for checking that. Good to hear. Just waiting on confirmation for another fix and will then get this released.
Hey, I just tested the workaround on Windows and it’s working!
For future reference, with the following diff to Raylib’s current Makefile I had success getting audio to work on Android with Raylib (all compilation done on a Linux box using a modified raylib-game-template setup):
Thanks to all participants of this issue 👍
Both Android backends (OpenSL and AAudio) should be enabled by default unless MA_NO_* is used. Something helpful might be to enable MA_DEBUG_OUTPUT and post the output here.
The defines have changed! You now need to define MA_ANDROID
Hey @mackron, I have tested the new
miniaudio.h
after reversingraudio.c
and it seems to be working! I get> Backend: miniaudio / AAudio
as expected and the app indeed plays the sound.@lorenzo774, The
#define MA_SUPPORT_AAUDIO
and#define MA_ENABLE_AAUDIO
seems right, but note thatminiaudio.h
is inside theexternal
folder, which is why you should enter:#include "external/miniaudio.h"
. Hope this will do the trick, and if not maybe even better for you would be to download the updatedminiaudio.h
that @mackron edited. Of course don’t forget to compile and deletelibraylib.a
from yourandroid.<project name>/lib/arm64-v8a
folder before you create the apk file.OK, that’s your problem. If you’re compiling on Linux, only Linux backends will be compiled in, none of which will work on Android. There is no way to enable non-Linux backends when building on Linux.