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

Most upvoted comments

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):

diff --git a/src/Makefile b/src/Makefile
index 87d76a65..fc5d171e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -535,6 +535,10 @@ ifeq ($(RAYLIB_MODULE_MODELS),TRUE)
 endif
 ifeq ($(RAYLIB_MODULE_AUDIO),TRUE)
     OBJS += raudio.o
+    # XXX: https://github.com/raysan5/raylib/issues/2118
+    ifeq ($(PLATFORM),PLATFORM_ANDROID)
+      CFLAGS += -DMA_SUPPORT_AAUDIO
+    endif
 endif
 ifeq ($(RAYLIB_MODULE_RAYGUI),TRUE)
     OBJS += raygui.o

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 reversing raudio.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 that miniaudio.h is inside the external 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 updated miniaudio.h that @mackron edited. Of course don’t forget to compile and delete libraylib.a from your android.<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.