Fmod and Android

I am using fmod for Defold.

The game runs fine via the editor (and I can hear sfx and music) but when I bundle it for Android it crashes immediately and I see this in the log:

ERROR:SCRIPT: game/audio/script/audio.lua:6: attempt to index global ‘fmod’ (a nil value)
08-31 15:30:31.669 6623 6652 E defold : stack traceback:
08-31 15:30:31.669 6623 6652 E defold : game/audio/script/audio.lua:6: in main chunk
08-31 15:30:31.669 6623 6652 E defold : [C]: in function ‘require’
08-31 15:30:31.669 6623 6652 E defold : game/main/scripts/main.script:10: in main chunk

Line 6 in audio.lua is

M.STOP_IMMEDIATE = fmod.STUDIO_STOP_IMMEDIATE

What am I doing wrong?

Thanks!

EDIT: fmod is indeed nil… I don’t understand why… please, any help is highly appreciated!

Are you perhaps referencing fmod before the extension has been initialised? You seem to be referencing fmod from game/audio/script/audio.lua and the question is if this happens outside the scope of the script lifecycle functions.

I have replaced fmod.STUDIO_STOP_IMMEDIATE by 1 (this should be the value) to avoid calling fmod before “initialization”. But fmod is still nil also in the main collection init function.

Moreover it seems to me that there is no init function I have to call for fmod. From https://github.com/dapetcu21/defold-fmod:
"
A fully initialised instance of FMOD::Studio::System is exposed to Lua as fmod.studio.system and the corresponding instance of FMOD::System (the low level system), is exposed as fmod.system.
"

I still don’t understand.

Is it the correct build? Have you checked that the fmod functions are inside the executable?

I don’t understand “Is it the correct build”… How can I check that fmod functions are in the executable?

These are C++ symbols that are built into the executable.
To see what symbols are in the executable (if they’re not hidden), you can for instance use the command nm. (Search for man nm.

Since we know the extension adds the functions with the name FMOD, we can search for that.

In the terminal, write:

$ nm ./build/armv7-android/dmengine.so | grep FMOD

And you should see if the executable contains those functions.

1 Like

nm libjackRedrum.so | grep FMOD

gives a (very long) list of functions containing FMOD, the first lines are:

000000000004ab30 t DefoldFMOD
000000000041ed70 b DefoldFMOD151
000000000004b68c t FMODBridge_activateApp
000000000004ba80 t FMODBridge_attachJNI
000000000004c680 t FMODBridge_check_ptr_void_size
000000000004c2b8 t FMODBridge_cleanupLibraries

Then it seems like the executable contains the correct FMod extension.

Next question, does the bundle contain the same executable?
Unzip the .apk and compare the checksums of your local libjackRedrum.so and the one in the unzipped apk. E.g. using md5.

1 Like

I am going to check this, but I would say that the .so is referring to the .apk I have uploaded on the device since they have been created together by the bundle command…

Well, I’m just listing the things I usually check when I encounter things like this.

1 Like

md5sum returns the same value for the two .so files. Moreover, I have checked that the FMOD functions are in the libjackRedrum.so extracted from the apk

For calls to extensions like FMOD we wrap them in checks like this.

if fmod then 
   ... -- normal code goes here
end

Next something we do is to delay init to give everything time to init and register. What this looks like is in our main collection for anything secondary to the main.script we delay it for the most part. To do this in each script’s init we send a message to itself and then when it gets that message on the next frame we then call init_actual.

You should test building the FMOD example project for Android and see if it works.

The last time I built a project for Android with FMOD it did work. It was some months ago though.

1 Like

I have delayed the main.script init by 0.1 second but fmod is still nil.

Can you disable using fmod at all and just print(fmod) in update to see if it is ever there? If the example doesn’t work then it should give more insight that there is a problem.

Also the build of the FMOD example sees fmod as nil on Android… (indeed it prints on screen “Sorry! Your platform is mot yet supported” and this is done by checking if fmod is nil)

This is all I see from the log:

--------- beginning of crash
--------- beginning of system
--------- beginning of main
08-31 21:15:40.742 22576 22599 I defold : INFO:DLIB: Log server started on port 41601
08-31 21:15:40.791 22576 22599 I defold : INFO:ENGINE: Engine service started on port 8001
08-31 21:15:40.791 22576 22599 I defold : INFO:ENGINE: Defold Engine 1.2.172 (dedf1ed)
08-31 21:15:40.800 22576 22599 I defold : INFO:ENGINE: Loading data from: dmanif:game.dmanifest
08-31 21:15:40.868 22576 22599 I defold : INFO:ENGINE: Initialised sound device ‘default’
08-31 21:15:40.868 22576 22599 I defold :
08-31 21:15:40.953 22576 22599 W defold : WARNING:ENGINE: Unknown Android input method [KeyEvent], defaulting to key events
08-31 21:15:40.958 22576 22599 I defold : INFO:DLIB: SSDP: Started on address 192.168.1.3
08-31 21:15:41.205 22576 22599 E defold : ERROR:PROFILER: Could not open /proc/stat

fmod is nil for sure also in update!

Does this project have audio playing on your device? https://play.google.com/store/apps/details?id=com.subsoap.fsh

Have you tested other devices? What’s the model?

1 Like

Faerie Solitaire has sound!

Here’s some config info for it

game.project

[fmod]
speaker_mode = stereo
lib_path = _fmod/res
live_update = 0

It uses the master.zip, the lib files have a date of 2/27/2020 so you might try an older version to see if it works on Android if there is an older one from before that date.

These are the build options I am using