Qt application with FMOD audio library crashes on launch on Android

46 views Asked by At

I made an example that works on desktop when I build it to EXE but crashes when I run APK on smartphone. I use 2.02.16 API version, JDK 17, NDK 22, Qt 6.2.4, and Redmi 4x (Android 7)

Settings:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

INCLUDEPATH += $$PWD/libs/fmod-2.2.16/inc

contains(ANDROID_TARGET_ARCH, armeabi-v7a)
{
    ANDROID_EXTRA_LIBS += $$PWD/jniLibs/armeabi-v7a/libfmod.so
}

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    assets.qrc

APK is created after 1-2 minutes without problems. This is a source code of my example:

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QtWidgets/QWidget>
#include <fmod.h>

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    FMOD_SYSTEM *m_pSystem;
    FMOD_SOUND *m_pSound;
};
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include <QtCore/QDebug>
#include <QtCore/QFile>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    FMOD_System_Create(&m_pSystem, FMOD_VERSION);
    FMOD_System_Init(m_pSystem, 32, FMOD_INIT_NORMAL, 0);

    QString soundPath(":/assets/audio/music.wav");
    QFile f(soundPath);
    if (!f.open(QIODevice::ReadOnly))
    {
        qDebug() << "Faild to open the file: " << soundPath;
        return;
    }
    QByteArray soundData = f.readAll();

    FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO();
    exinfo->length = static_cast<unsigned int>(soundData.length());
    exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    FMOD_System_CreateSound(m_pSystem, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_pSound);

    FMOD_Sound_SetMode(m_pSound, FMOD_LOOP_OFF);

    FMOD_System_PlaySound(m_pSystem, m_pSound, 0, false, 0);
}

Widget::~Widget()
{
}

main.cpp

#include "widget.h"

#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}

I use armeabi-v7a to build a release:

![image|419x133](upload://pQbknE9tF5IHq1aSRs1qrmiqecl.png)

I tried without FMOD and it runs on smartphone without problems. But my example above crashes with this report (scroll to the end of the first post on the following link): https://qa.fmod.com/t/qt-application-with-fmod-crashes-on-launch-on-android/20561

0

There are 0 answers